-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path07-Unions.sql
19 lines (15 loc) · 1006 Bytes
/
07-Unions.sql
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
-- UNIONS (combine rows from separate tables)
select age, gender from employee_demographics
union
select first_name, last_name from employee_salary; # this statement will give age, gender, first_name, last_name but under the column names age and gender.
select first_name, last_name from employee_demographics
union
select first_name, last_name from employee_salary; # by default union is distict union so, redundent values are ommited
select first_name, last_name from employee_demographics
union all # 'union all' will remove the distinct feature and will also display similar values
select first_name, last_name from employee_salary;
select first_name, last_name, 'Old man' as label from employee_demographics where age>=40 and gender = 'Male'
union
select first_name, last_name, 'Old woman' as label from employee_demographics where age>=40 and gender = 'Female'
union
select first_name,last_name, 'Expensive' as label from employee_salary where salary>=75000 order by first_name,last_name;