Professional Documents
Culture Documents
Lecture's Objectives /1 - SQL: Dr. Ala Al-Zobaidie
Lecture's Objectives /1 - SQL: Dr. Ala Al-Zobaidie
Lecture 8 1
DBDI / SQL 30/05/2007
Lecture 8 2
DBDI / SQL 30/05/2007
Example 5.1 All Columns, All Rows Example 5.1 All Columns, All Rows
SELECT *
FROM Staff;
Example 5.2 Specific Columns, All Example 5.2 Specific Columns, All
Rows Rows
Produce a list of salaries for all staff,
showing only staff number, first and last
names, and salary.
List the property numbers of all properties • Use DISTINCT to eliminate duplicates:
that have been viewed. SELECT DISTINCT propertyNo
FROM Viewing;
SELECT propertyNo
FROM Viewing;
Lecture 8 3
DBDI / SQL 30/05/2007
Produce a list of monthly salaries for all staff, • To name column, use AS clause:
showing staff number, first and last names, and
salary details.
SELECT staffNo, fName, lName, salary/12 SELECT staffNo, fName, lName,
FROM Staff; salary/12 AS monthlySalary
FROM Staff;
Example 5.7 Range Search Condition Example 5.7 Range Search Condition
Lecture 8 4
DBDI / SQL 30/05/2007
• Also a negated version NOT BETWEEN. List all managers and supervisors.
• BETWEEN does not add much to SQL's
SELECT staffNo, fName, lName, position
expressive power Could also write:
FROM Staff
SELECT staffNo, fName, lName, position, WHERE position IN ('Manager', ‘Supervisor');
salary
FROM Staff
WHERE salary>=20000 AND salary <= 30000;
Lecture 8 5
DBDI / SQL 30/05/2007
Example 5.10 NULL Search Condition Example 5.11 Single Column Ordering
Example 5.11 Single Column Ordering Example 5.12 Multiple Column Ordering
Example 5.12 Multiple Column Ordering Example 5.12 Multiple Column Ordering
Lecture 8 6
DBDI / SQL 30/05/2007
Summary
• Purpose of SQL
• History and Standards
• Basic Syntax of a Select Statement
• The basic 5 Search Conditions
• Examples from DreamHome
• Aliases
• Nested Query
30/05/2007 DBDI / SQL 39
Lecture 8 7