use tsql2012;
select country, region, city from hr.employees
union all
select country, region, city from sales.customers;
select country, region, city from hr.employees
union
select country, region, city from sales.customers;
select country, region, city from hr.employees
intersect
select country, region, city from sales.customers;
select row_number() over(partition by country, region, city order by (select 0)) as rownum,
country, region, city
from hr.employees
intersect
select row_number() over(partition by country, region, city order by (select 0)) as rownum,
country, region, city
from sales.customers;
with intersect_all
as
(select row_number() over(partition by country, region, city order by (select 0)) as rownum,
country, region, city
from sales.customers
intersect
select row_number() over(partition by country, region, city order by (select 0)) as rownum,
country, region, city
from hr.employees)
select country, region, city from intersect_all;
select country, region, city from hr.employees
except
select country, region, city from sales.customers;
select country, region, city from sales.customers
except
select country, region, city from hr.employees;
with except_all
as
(select row_number() over(partition by country, region, city order by (select 0)) as rownum,
country, region, city
from hr.employees
except
select row_number() over(partition by country, region, city order by(select 0)) as rownum,
country, region, city
from sales.customers)
select country, region, city from except_all;
select country, count(*) as numlocations
from (select country, region, city from hr.employees
union
select country, region, city from sales.customers) as U
group by u.country;
select empid, orderid, orderdate
from (select top(2) empid, orderid, orderdate
from sales.orders
where empid = 3