SELECT Statement


The SELECT Statement selects fields (columns of data) from a table. The tabular result is stored in a result table (called the result set). The syntax is SELECT fieldname FROM tablename. Run the query SELECT NAME_LAST FROM People:

mysql> select NAME_LAST from people;
+-----------+ 
| NAME_LAST | 
+-----------+ 
| Jones     | 
| Jones     | 
| Smith     | 
| Smith     | 
+-----------+ 
4 rows in set (0.00 sec) mysql>

To select more than one field, use commas. Run the query SELECT NAME_LAST, NAME_FIRST FROM People:

mysql> select NAME_LAST, NAME_FIRST from people;
+-----------+------------+ 
| NAME_LAST | NAME_FIRST | 
+-----------+------------+ 
| Jones     | Robert     | 
| Jones     | Tyler      | 
| Smith     | Barbara    | 
| Smith     | Nancy      | 
+-----------+------------+ 
4 rows in set (0.00 sec) mysql>

An asterisk ( * ) is the wild-card character. Run SELECT * FROM People to get the entire table:

mysql> select * from people;
+--------+-----------+------------+----+------------+ 
| ID     | NAME_LAST | NAME_FIRST | MI | POSITION   | 
+--------+-----------+------------+----+------------+ 
| rjones | Jones     | Robert     | T  | Manager    | 
| tjones | Jones     | Tyler      | R  | Technician | 
| bsmith | Smith     | Barbara    | N  | Clerk      | 
| nsmith | Smith     | Nancy      | B  | Manager    | 
+--------+-----------+------------+----+------------+ 
4 rows in set (0.00 sec) mysql>

Functions   < <  PREVIOUS   Table of Contents NEXT  > >   Where, Like

Developed with HTML-Kit
Sandersongs Web Tutorials
Contact the Webmasterwith comments.
©2024, by Bill Sanders, all rights reserved.
This domain had 3,144 different visits in the last 30 days.
http://sandersongs.com/PHPsqlCourse/SQL06.php
This page was last modified on our server on 11 Jul 2021
and last refreshed on our server at 10:32 pm, UTC
This file took 0.01167 seconds to process.