-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcity_names.sql
More file actions
34 lines (30 loc) · 797 Bytes
/
city_names.sql
File metadata and controls
34 lines (30 loc) · 797 Bytes
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
--Determine the names of capital cities that are not listed in the cities table.
SELECT capital
FROM countries
-- Set theory clause
EXCEPT
SELECT name
FROM cities
ORDER BY capital;
--which countries also have a city with the same name as their country name?
SELECT name
FROM countries
-- Set theory clause
INTERSECT
SELECT name
FROM cities;
--country codes included in either economies or currencies but not in populations
SELECT name, country_code
FROM cities AS c1
WHERE country_code IN
(SELECT e.code
FROM economies AS e
-- Get all additional (unique) values of the field from currencies AS c2
UNION
SELECT c2.code
FROM currencies AS c2
-- Exclude those appearing in populations AS p
EXCEPT
SELECT p.country_code
FROM populations AS p
);