SELECT statement overview
The SELECT statement is constructed of clauses that let you look at data in a relational database. These clauses let you select columns and rows from one or more database tables or views, specify one or more conditions, order and summarize the data, and put the selected data in a temporary table.
This
chapter shows how to use five SELECT statement clauses. If you include
all five of these clauses, they must appear in the SELECT statement
in the following order:
- Projection clause
- FROM clause
- WHERE clause
- ORDER BY clause
- INTO TEMP clause
Only the Projection clause and FROM clause are required.
These two clauses form the basis for every database query, because
they specify the column values to be retrieved, and the tables that
contain those columns. Use one or more of the other clauses from the
following list:
- Add a WHERE clause to select specific rows or create a join condition.
- Add an ORDER BY clause to change the order in which data is produced.
- Add an INTO TEMP clause to save the results as a table for further queries.
Two additional SELECT statement clauses, GROUP BY and HAVING, let you perform more complex data retrieval. They are introduced in Compose advanced SELECT statements. Another clause, INTO, specifies the program or host variable to receive data from a SELECT statement in an application program. Complete syntax and rules for using the SELECT statement are in the HCL OneDB™ Guide to SQL: Syntax.