You are on page 1of 11

Set Operations

By Dr. Ghazi Al-Naymat

1
Company DB

• Note: In the forthcoming SQL statements, all table names used C_[tablename] this is
used because I have other tables with similar names to the tables in the company DB
example.

2
Union Example
• List the Lname of all employees who have dependents or working on
project ProductY?
• We break out the question for demonstration purposes
1- List the Lname of all employees who have dependents

3
2- working on project ProductY?

4
3- List the Lname of all employees who have dependents or working on
project ProductY?: Using Union

5
Output

Union =

6
In case if we use AND, OR instead of
UNION
• Or

….
• And

• Both wrong output.


7
Intersect Example
• Make a list of all project numbers for projects that involve an
employee whose last name is 'Smith' and an employee whose last
name is ‘Wong’ as workers.

8
In case if we use AND, OR instead of
INTERSECT

BOTH WRONG!

9
MINUS (EXCEPT) Example
• Make a list of all project numbers for projects that involve an
employee whose last name is 'Smith' but not an employee
whose last name is ‘Wong’ as workers.

10
In case if we use AND, OR instead of
MINUS

BOTH WRONG!

11

You might also like