Objectives
After completing this lesson, you should be able to do the
following:
Limit the rows that are retrieved by a query
Sort the rows that are retrieved by a query
Use ampersand substitution to restrict and sort output at
run time
2-2
Lesson Agenda
2-3
EMPLOYEES
retrieve all
employees in
department 90
2-4
2-5
2-6
2-7
Comparison Operators
Operator
=
Equal to
>
Greater than
>=
2-8
Meaning
<
Less than
<=
<>
Not equal to
BETWEEN
...AND...
IN(set)
LIKE
IS NULL
Is a null value
2-9
2 - 10
Upper limit
2 - 11
2 - 12
first_name
employees
first_name LIKE 'S%' ;
2 - 13
You can use the ESCAPE identifier to search for the actual %
and _ symbols.
2 - 14
Operator
2 - 15
Meaning
AND
OR
NOT
2 - 16
2 - 17
2 - 18
Lesson Agenda
2 - 19
Rules of Precedence
Operator
Meaning
Arithmetic operators
Concatenation operator
Comparison conditions
[NOT] BETWEEN
Not equal to
OR logical condition
2 - 20
Rules of Precedence
2 - 21
SELECT
FROM
WHERE
OR
AND
SELECT
FROM
WHERE
OR
AND
Lesson Agenda
2 - 22
2 - 23
Sorting
2 - 24
Sorting
2 - 25
Lesson Agenda
2 - 26
Substitution Variables
... salary = ?
department_id = ?
... last_name = ? ...
I want
to query
different
values.
2 - 27
Substitution Variables
2 - 28
WHERE conditions
ORDER BY clauses
Column expressions
Table names
Entire SELECT statements
2 - 29
2 - 30
2 - 31
2 - 32
2 - 33
Lesson Agenda
2 - 34
2 - 35
2 - 36
Quiz
Which of the following are valid operators for the WHERE clause?
1. >=
2. IS NULL
3. !=
4. IS LIKE
5. IN BETWEEN
6. <>
2 - 37
Summary
In this lesson, you should have learned how to:
Use the WHERE clause to restrict rows of output:
Use the comparison conditions
Use the BETWEEN, IN, LIKE, and NULL operators
Apply the logical AND, OR, and NOT operators
2 - 38
Practice 2: Overview
This practice covers the following topics:
Selecting data and changing the order of the rows
that are displayed
Restricting rows by using the WHERE clause
Sorting rows by using the ORDER BY clause
Using substitution variables to add flexibility to your
SQL SELECT statements
2 - 39