SQL Reference

Chapter 2 | Supported standards 11
WHERE clause
The WHERE clause specifies the conditions that records must meet to be retrieved. The WHERE
clause contains conditions in the form:
WHERE expr1 rel_operator expr2
expr1 and expr2 can be field names, constant values, or expressions.
rel_operator is the re
lational operator that links the two expressions.
Example
Retrieve the names of employees who make $20,000 or more.
SELECT last_name,first_name FROM emp WHERE salary >= 20000
The WHERE clause can also use expressions such as these:
WHERE expr1 IS NULL
WHERE NOT expr2
Note If you use fully qualified names in the SELECT (projection) list, you must also use fully
qualified names in the related WHERE clause.
GROUP BY clause
The GROUP BY clause specifies the names of one or more fields by which the returned values
should be grouped. This clause is used to return a set of aggregate values. It has the following
format:
GROUP BY columns
The scope of the GROUP BY clause is the table expression in the FROM clause. As a result, the
column expressions specified by columns must be from the tables specified in the FROM clause.
A column expression can be one or more field names of the database table separated by commas.
Example
Sum the salaries in each department.
SELECT dept_id, SUM (salary) FROM emp GROUP BY dept_id
This statement returns one row for each distinct department ID.
Each row contains the department ID
and the sum of the salaries of the employees in the department.