More SQL Select: Database Systems Lecture 8
More SQL Select: Database Systems Lecture 8
• SQL SELECT
• WHERE clauses
• SELECT from multiple tables
• JOINs
• Aliases
• Table alias
SELECT ...
FROM table
AS newName
SQL says ‘AS’ is optional, but
Oracle doesn’t even accept it.
SELECT
Result: E.ID AS empID,
empID Name Dept
E.Name, W.Dept
FROM
124 Dipsy Marketing Employee E
125 La La Sales
125 La La Marketing WorksIn W
WHERE
E.ID = W.ID
Employee Employee
A B
Name Dept Name Dept
Dipsy Marketing Dipsy Marketing
La La Sales La La Sales
Tinky Sales Tinky Sales
Po Marketing Po Marketing
Sun Marketing Sun Marketing
A.Name
Dipsy
Po
Sun
Employee
Name Department Manager SELECT *
John Marketing Chris FROM Employee
Mary Marketing Chris WHERE Name NOT IN
Chris Marketing Jane (SELECT Manager
Peter Sales Jane FROM Employee)
Jane Management null
SELECT <columns>
• The set is always given by a subquery
FROM <tables>
WHERE NOT EXISTS
<set>
Employee SELECT *
FROM Employee AS E1
Name Department Manager
WHERE EXISTS
John Marketing Chris ( SELECT * FROM
Mary Marketing Chris
Employee AS E2
Chris Marketing Jane
WHERE E1.Name =
Peter Sales Jane
Jane Management null E2.Manager)
01 Jones 01 OOS OOS tjb
02 Chan 01 IHF IIT tjb
03 Hunt
02 OOS DBS bai
04 Jones
04 DBS IHF geb
ItemKey
itmID keyID
Note, this is one of the questions from last time, but there are
alternative solutions using subqueries, try solving this with a
query where you never list more than one table for a single
SELECT statement