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>