Using the WHERE Clause

From InterBase
Jump to: navigation, search

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.

Image 025.jpgUsing 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:
Green                T.J.            218
  1. Now display this statement again by clicking PrevQuery.gif 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: the ORDER BY clause is discussed starting on page 20.
SELECT last_name, first_name, phone_ext
FROM Employee
WHERE last_name > 'Green'
ORDER BY last_name

Advance To:

Search Conditions