Selecting columns

You can select columns from a table by specifying the table name in the FROM clause of a Select-From-Where (SFW) expression, and listing the names of the desired columns in the SELECT clause of the same SFW expression.

Be aware that the FROM clause can name only one table. If you want to retrieve data from a child table, use dot notation (that is, "parent.child").

To select all the columns of the table Users, use the short-hand "star" notation:

sql-> SELECT * FROM Users; 

The result as shown by the shell is:

 
 +----+-----------+----------+-----+--------+
 | id | firstname | lastname | age | income |
 +----+-----------+----------+-----+--------+
 |  3 | John      | Morgan   |  38 |   NULL |
 |  4 | Peter     | Smith    |  38 |  80000 |
 |  2 | John      | Anderson |  35 | 100000 |
 |  5 | Dana      | Scully   |  47 | 400000 |
 |  1 | David     | Morrison |  25 | 100000 |
 +----+-----------+----------+-----+--------+

5 rows returned 

To select specific column(s) from the table Users, include them as a comma separated list in the SELECT clause:

sql-> SELECT firstname, lastname, age FROM Users;
 +-----------+----------+-----+
 | firstname | lastname | age |
 +-----------+----------+-----+
 | John      | Morgan   |  38 |
 | David     | Morrison |  25 |
 | Dana      | Scully   |  47 |
 | Peter     | Smith    |  38 |
 | John      | Anderson |  35 |
 +-----------+----------+-----+

5 rows returned