Datasheet
Writing Simple Queries
29
are returned or operated upon where the data satisfies the logical condition(s) of the WHERE
clause. You can use column names or expressions in the
WHERE clause, but not column alias
names. The
WHERE clause follows the FROM clause in the SELECT statement.
How do you list the employees who work for department 90? The following example
shows how to limit the query to only the records belonging to department 90 by using a
WHERE clause:
SELECT first_name || ‘ ‘ || last_name “Name”, department_id
FROM employees
WHERE department_id = 90;
Name DEPARTMENT_ID
------------------------------------------- -------------
Steven King 90
Neena Kochhar 90
Lex De Haan 90
You need not include the column names in the SELECT clause to use them
in the
WHERE clause.
You can use various operators in Oracle 11g in the WHERE clause to limit the number of rows.
Comparison Operators
Comparison operators compare two values or expressions and give a Boolean result
of
TRUE, FALSE, or NULL. The comparison operators include those that test for equality,
inequality, less than, greater than, and value comparisons.
= (Equality)
The = operator tests for equality. The test evaluates to TRUE if the values or results of an
expression on both sides of the operator are equal.
SELECT first_name || ‘ ‘ || last_name “Name”, department_id
FROM employees
WHERE department_id = 90;
Name DEPARTMENT_ID
------------------------------------------- -------------
Steven King 90
Neena Kochhar 90
Lex De Haan 90
95127c01.indd 29 2/18/09 6:37:09 AM