ASA SQL User's Guide
Queries: Selecting Data from a Table
Query overview
You construct SELECT statements from clauses. In the following SELECT syntax, each new line is a separate clause. Only the more common clauses are listed here.
SELECT select-list
[ FROM table-expression ]
[ WHERE search-condition ]
[ GROUP BY column-name ]
[ HAVING search-condition ]
[ ORDER BY { expression | integer } ]
The clauses in the SELECT statement are as follows:
The SELECT clause specifies the columns you want to retrieve. It is the only required clause in the SELECT statement.
The FROM clause specifies the tables from which columns are pulled. It is required in all queries that retrieve data from tables. SELECT statements without FROM clauses have a different meaning, and this chapter does not discuss them.
Although most queries operate on tables, queries may also retrieve data from other objects that have columns and rows, including views, other queries (derived tables) and stored procedure result sets. For more information, see FROM clause.
The ON clause specifies how tables in the FROM clause are to be joined. It is used only for multi-table queries and is not discussed in this chapter.
For information on multi-table queries, see Joins: Retrieving Data from Several Tables.
The WHERE clause specifies the rows in the tables you want to see.
The GROUP BY clause allows you to aggregate data.
The HAVING clause specifies rows on which aggregate data is to be collected.
The ORDER BY clause sorts the rows in the result set. (By default, rows are returned from relational databases in an order that has no meaning.)
For information on GROUP BY, HAVING, and ORDER BY clauses, see Summarizing, Grouping and Sorting Query Results.
Most of the clauses are optional, but if they are included then they must appear in the correct order.
For more information about the SELECT statement syntax, see SELECT statement.