-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathset_operator.sql
More file actions
43 lines (37 loc) · 1.3 KB
/
set_operator.sql
File metadata and controls
43 lines (37 loc) · 1.3 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/*Rule :
number of columns selected for the queries must be the same
corresponding columns for the queries must have matched data type
The names of the columns need to be identical
Column names in the output are taken from the column names in the first select statement
Paratheses can be used to alter the sequence of execution
ORDER BY clause can appear only at the very end of the statement*/
/*The minus operator returns all rows found in one table but not the other*/
/*Display the current and previous job details of all employees. Display each employee only once (eliminate duplicate)*/
SELECT employee_id,job_id
FROM employees
union
SELECT employee_id,job_id
FROM job_history
/*Intersect operator returns all rows common to both tables*/
/*Employees that chaged jobs but have now gone back to doing the same job they did previously*/
SELECT employee_id,job_id
FROM employees
intersect
SELECT employee_id,job_id
FROM job_history
SELECT location_id,department_name,to_char(null)
FROM departments
union
SELECT location_id,to_char(null),state_province
FROM locations;
SELECT employee_id,salary
FROM employees
union
SELECT employee_id,0
FROM job_history
SELECT employee_id,salary
FROM employees
union
SELECT employee_id,0
FROM job_history
order by 1