Restricting Row Retrieval with WHERE
Go Up to Understanding Data Retrieval with SELECT
In a query, the WHERE
clause specifies the data a row must (or must not) contain to be retrieved.
In singleton selects, where a query must only return one row, WHERE
is mandatory unless a select procedure specified in the FROM
clause returns only one row itself.
In SELECT
statements within DECLARE CURSOR
statements, the WHERE
clause is optional. If the WHERE
clause is omitted, a query returns all rows in the table. To retrieve a subset of rows in a table, a cursor declaration must include a WHERE
clause.
The simple syntax for WHERE
is:
WHERE <search_condition>
For example, the following simple WHERE
clause tests a row to see if the
DEPARTMENT column is “Publications”:
WHERE DEPARTMENT = 'Publications'