InterBase Quick Start: Part IV - Using the WHERE Clause
Go Up to InterBase Quick Start: Part IV - Retrieving Data
The WHERE clause follows the SELECT and FROM clauses. It must precede the ORDER BY clause if one is used. The WHERE clause tests data to see whether it meets certain conditions, and the SELECT statement returns only the rows that meet the WHERE condition. The WHERE clause lies at the heart of database usage, because it is the point at which you state exactly what you want. It seems complex at first glance, but the complexity exists to allow you to be precise in your requests for data.
Using WHERE
1. Enter the following statement to return only rows for which “Green” is the value in the last_name column.
SELECT last_name, first_name, phone_ext
FROM Employee
WHERE last_name = 'Green'
The query should return one row:
last_name | first_name | phone_ext |
---|---|---|
Green | T.J. | 218 |
2. Now display this statement again by clicking and change the equal sign to a greater than sign. This retrieves rows for which the last name is alphabetically greater than (after) “Green.” There should be 29 rows.
- Something extra: To make the results more readable, execute the last query once again, but add an ORDER BY clause. This is just a preview. For more information on the ORDER BY clause, see Using ORDER BY to Arrange Rows.
SELECT last_name, first_name, phone_ext
FROM Employee
WHERE last_name > 'Green'
ORDER BY last_name