SQL I - 1x04 FRANZ 17
SQL I - 1x04 FRANZ 17
Lesson Agenda
– Limiting rows with:
• The WHERE clause
• The comparison conditions using =, <=, BETWEEN, IN,
LIKE, and NULL operators
• Logical conditions using AND, OR, and NOT operators
– Rules of precedence for operators in an expression
– Sorting rows using the ORDER BY clause
– Substitution variables
– DEFINE and VERIFY commands
Substitution Variables
... salary = ? …
… department_id = ? …
... last_name = ? ...
I want
to query
different
values.
1
14/11/2016
Substitution Variables
– Use substitution variables to:
• Temporarily store values with single-ampersand (&) and double-
ampersand (&&) substitution
– Use substitution variables to supplement the following:
• WHERE conditions
• ORDER BY clauses
• Column expressions
• Table names
• Entire SELECT statements
2
14/11/2016
3
14/11/2016
4
14/11/2016
Lesson Agenda
– Limiting rows with:
• The WHERE clause
• The comparison conditions using =, <=, BETWEEN, IN,
LIKE, and NULL operators
• Logical conditions using AND, OR, and NOT operators
– Rules of precedence for operators in an expression
– Sorting rows using the ORDER BY clause
– Substitution variables
– DEFINE and VERIFY commands
UNDEFINE employee_num
5
14/11/2016
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
– Use the ORDER BY clause to sort rows of output:
SELECT *|{[DISTINCT] column|expression [alias],...}
FROM table
[WHERE condition(s)]
[ORDER BY {column, expr, alias} [ASC|DESC]] ;
6
14/11/2016
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