Reputation: 21
Here's my table "Earth"
I need to find all records / rows, in which people share
In this query, I can't use any specific country, state, or city names. Therefore is there a query I can use, that will still return for example two or more people who share the same country, state, and city?
Upvotes: 1
Views: 45
Reputation: 1269447
What you are looking for is a self join. It would look something like this:
select t1.personid, t2.personid, t1.country, t1.state, t1.city
from t t1 join
t t2
on t1.country = t2.country and t1.state = t2.state and t1.city = t2.city and
t1.personid < t2.personid;
Upvotes: 4