Query a table
To query a table, use the SELECT command. The select command is
divided into three parts:
- The columns to return
- The tables from which to retrieve data
- Any restrictions
For example, to list all the rows of the table weather, enter:
MYDB.SCHEMA(USER)=> SELECT * FROM weather;
To specify expressions in the target list, enter:
MYDB.SCHEMA(USER)=> SELECT city, (temp_hi+temp_lo)/2 AS temp_avg, date
FROM weather;
In this example, you rename the columns temp_hi and temp_lo as temp_avg by using an AS clause.
You can use Boolean operators (AND, OR, and NOT) in the qualification
of a query. For example, to retrieve the weather of San Francisco
on rainy days, enter:
MYDB.SCHEMA(USER)=> SELECT * FROM weather WHERE city = 'San Francisco' AND
prcp > 0.0;
To specify that the result of a select is returned in sorted order,
enter:
MYDB.SCHEMA(USER)=> SELECT DISTINCT city FROM weather ORDER BY city;