Reputation: 105
given that there are 2 such entities
city(name, country, population)
country(code, name, capital, population)
and the question is that there exist cities in different countries that have the same name. For instance, paris in texas, usa, and paris in france. we assume, however, that every city in one country has a unique name in that country. find the names of cities that have a unique name.
would this work then
SELECT DISTINCT c1.name
FROM city c1, city c2
WHERE c1.name<>c2.name;
Upvotes: 0
Views: 1049
Reputation: 3808
This will find all the cities that are unique in the database.
SELECT name
FROM city
Group by city
Having count(city) = 1
Upvotes: 1