602SQL Documentation Index  

Queries in SQL (SELECT)

Queries in SQL search the database and construct a record set that fulfill the selected criteria. This set is called the query result. If each records contains only a single value (a single column), it is referred to as a scalar query.

The most used form of a query is the SELECT...FROM...WHERE... type. This query type is described in the query specification section. According to the SQL 2 standard, complex queries can be created by joining simple queries using the UNION, INTERSECT and EXCEPT operators. These operators are called query expressions.

You can SELECT a single table, the result of a query (VIEW) stored in the database, any subquery enclosed in parenthesis, or a join of two tables using the JOIN operation. These possibilities are described in the generalized table section.

A query in itself is not a statement, however, it may be used in many statements (e.g. INSERT, DECLARE CURSOR, CREATE VIEW). It is necessary to distinguish a query and the SELECT INTO statement that has a similar syntax, but is used for assigning query results into variables.

If there is a syntax error in the query definition a compilation error occurs. Optimization is performed after a successful compilation.


List of topics: