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.
©2017, by Bill Sanders, all rights reserved.
This domain had 3,987 different visits in the last 30 days.
435,553 hits on this domain since 24 Nov 2006.
http://www.sandersongs.com/PHPsqlCourse/SQL06.php
This page was last modified on our server on 4 Jun 2008
and last refreshed on our server at 3:55 am, MST
This file took 0.00891 seconds to process.