To retrieve data from a table, you execute a query using an SQL SELECT statement. The statement is divided into:
A select list (the part that lists the columns to return)
A table list (the part that lists the tables from which to retrieve the data)
An optional qualification (the part that specifies any restrictions)
The following query lists all columns of all employees in the table in no particular order.
Here, “*” in the select list means all columns. The following is the output from this query.
You can specify any arbitrary expression in the select list. For example, you can do:
Notice how the AS clause is used to relabel the output column. The AS clause is optional.
You can qualify a query by adding a WHERE clause that specifies the rows you want. The WHERE clause contains a Boolean (truth value) expression. Only rows for which the Boolean expression is true are returned. The usual Boolean operators (AND, OR, and NOT) are allowed in the qualification. For example, the following retrieves the employees in department 20 with salaries over $1000.00:
You can request to return the results of a query in sorted order:
You can request to remove duplicate rows from the result of a query: