-1

if I have a mysql table person and I want to find the person.id's of the people that have same name and from the same country, how would I do that?

something like:

select * 
from person p 
join person p2 
where p.country = p2.country and p.name = p2.name

but the example above if obviously not the way to go :\

Joakim Danielson
  • 43,251
  • 5
  • 22
  • 52
JohnBigs
  • 2,691
  • 3
  • 31
  • 61

2 Answers2

0

Your JOIN is incorrect, try

SELECT p.id as first, p2.id as duplicate 
FROM person p 
JOIN person p2 ON p.country = p2.country AND p.name = p2.name
Joakim Danielson
  • 43,251
  • 5
  • 22
  • 52
0

You are using Where keyword however in sql we always use ON with joins so

replace

where  p.country = p2.country and p.name = p2.name

to

ON  p.country = p2.country and p.name = p2.name
Ayaz Ali Shah
  • 3,453
  • 9
  • 36
  • 68