Standards and
compatibility
Examples
WHERE clause
This clause specifies which rows will be selected from
the tables named in the FROM clause. It is also used to do joins between
multiple tables. This is accomplished by putting a condition in the WHERE
clause that relates a column or group of columns from one table with a
column or group of columns from another table. Both tables must be listed in
the FROM clause.
$
For more information, see "Search conditions" on page 239.
GROUP BY clause
You can group by columns, alias names, or functions.
The result of the query contains one row for each distinct set of values in the
named columns, aliases, or functions. All NULL-containing rows are treated
as a single set. The resulting rows are often referred to as groups since there
is one row in the result for each group of rows from the table list. Aggregate
functions can then be applied to these groups to get meaningful results.
When GROUP BY is used, the select-list, HAVING clause, and ORDER BY
clause must not reference any identifier that is not named in the GROUP BY
clause. The exception is that the select-list and HAVING clause may contain
aggregate functions.
HAVING clause
This clause selects rows based on the group values and
not on the individual row values. The HAVING clause can only be used if
either the statement has a GROUP BY clause or the select list consists solely
of aggregate functions. Any column names referenced in the HAVING
clause must either be in the GROUP BY clause or be used as a parameter to
an aggregate function in the HAVING clause.
ORDER BY clause
This clause sorts the results of a query. Each item in
the ORDER BY list can be labeled as ASC for ascending order (the default)
or DESC for descending order. If the expression is an integer n, then the
query results will be sorted by the n'th item in the select list.
In embedded SQL, the SELECT statement is used for retrieving results from
the database and placing the values into host variables via the INTO clause.
The SELECT statement must return only one row. For multiple row queries,
you must use cursors.
♦
Entry level feature. The complexity of the SELECT statement
SQL/92
means that you should check individual clauses against the standard.
♦
Sybase
Supported by Adaptive Server Enterprise, with some
differences in syntax.
♦
How many employees are there?
SELECT count(*)
FROM Employee;
♦
List all customers and the total value of their orders.
Chapter 9 SQL Statements
603
Need help?
Do you have a question about the Adaptive Server Anywhere and is the answer not in the manual?
Questions and answers