![]() |
SQL-J Language Reference
|
Reference Manual |
SelectExpressionA SelectExpression is the basic SELECT-FROM-WHERE construct used to build a table value based on filtering and projecting values from other tables. Syntax
SELECT [ DISTINCT | ALL ] SelectItem [ , SelectItem ]* SelectItem
{ The SELECT clause contains a list of expressions and an optional quantifier that is applied to the results of the FROM clause and the WHERE clause. If DISTINCT is specified, only one copy of any row value is included in the result. Nulls are considered duplicates of one another for the purposes of DISTINCT. If no quantifier, or ALL, is specified, no rows are removed from the result in applying the SELECT clause (ALL is the default). A SelectItem projects one or more result column values for a table result being constructed in a SelectExpression. The result of the FROM clause is the cross product of the FROM items. The WHERE clause can further qualify this result. The WHERE clause causes rows to be filtered from the result based on a boolean expression. Only rows for which the expression evaluates to TRUE are returned in the result. The GROUP BY clause groups rows in the result into subsets that have matching values for one or more columns. GROUP BY clauses are typically used with aggregates. If there is a GROUP BY clause, the SELECT clause must contain only aggregates or grouping columns. If you want to include a non-grouped column in the SELECT clause, include the column in an aggregate expression. For example:
-- to find the number of hotels in each city If there is no GROUP BY clause, but a SelectItem contains an aggregate not in a subquery, the query is implicitly grouped. The entire table is the single group. The HAVING clause restricts a grouped table, specifying a search condition (much like a WHERE clause) that can refer only to grouping columns or aggregates from the current scope. The HAVING clause is applied to each group of the grouped table. If the HAVING clause evaluates to TRUE, the row is retained for further processing. If the HAVING clause evaluates to FALSE or NULL, the row is discarded. If there is a HAVING clause but no GROUP BY, the table is implicitly grouped into one group for the entire table. Cloudscape processes a SelectExpression in the following order: The result of a SelectExpression is always a table. When a query does not have a FROM clause (when you are constructing a value, not getting data out of a table), you use a VALUES statement, not a SelectExpression. For example: See VALUES expression. The * Wildcard* expands to all columns in the tables in the associated FROM clause. TableName.* and CorrelationName.* expand to all columns in the identified table. That table must be listed in the associated FROM clause. Naming ColumnsYou can name a SelectItem column using the AS clause. When the SelectExpression appears in a UNION, the names from the first SelectExpression are taken as the names for the columns in the result of the UNION. If a column of a SelectItem is not a simple ColumnReference expression or named with an AS clause, it is given a generated unique name. These column names are useful in several cases:
Java Data TypesDISTINCT and GROUP BY require sorting and so are not permitted with Java data types unless they are orderable. For information, see Orderable Java Data Types. SelectExpression Examples-- this example shows SELECT-FROM-WHERE
-- This example shows the use of the DISTINCT clause
-- This example shows how to rename an expression |
|
![]() Cloudscape Version 3.6 For information about Cloudscape technical support, go to: www.cloudscape.com/support/.Copyright © 1998, 1999, 2000 Informix Software, Inc. All rights reserved. |