user3345791
user3345791

Reputation: 105

SQL query tutorial

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

Answers (1)

WorkSmarter
WorkSmarter

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

Related Questions