Valid in: SQL and DBProc
The Select (interactive) statement returns values from tables or views.
The Select (interactive) statement has the following format:
SELECT [FIRST rowCount] [ALL | DISTINCT] * | expression [AS result_column]
{, expression [[AS] result_column]}
[FROM from_source {, from_source}
[WHERE search_condition] WHERE (clause)
[GROUP BY expression{, expression}] GROUP BY (clause)
[HAVING search_condition] HAVING (clause)
{UNION [ALL]
(select)
[ORDER BY ordering-expression [ASC | DESC]
{, ordering-expression [ASC | DESC]}];
The Select (interactive) statement returns values from one or more specified tables or views, in the form of a single result table. Using the various clauses of the select statement, the following can be specified:
This statement description presents details of the select statement in interactive SQL (ISQL). In ISQL the results of a query are displayed on your terminal. In embedded SQL (ESQL), results are returned in host language variables. For details about using the select statement in ESQL, see Select (embedded).
Tip: User consumption of computing resources can be restricted during queries (selects) using the grant statement. Specifically, limits can be specified for I/O and for the number of rows returned. If the DBMS query optimizer estimates that a select exceeds the specified limits, the query is not executed. For details, see Grant (privilege).
Note: If II_DECIMAL is set to comma, be sure that when SQL syntax requires a comma (such as a list of table columns or SQL functions with several parameters), that the comma is followed by a space. For example:
select col1, ifnull(col2, 0), left(col4, 22) from t1:
The following sections describe the clauses of the select statement, explain how to create simple queries, and explain how the results of a query are obtained.