Nathaniel Hodges Nathaniel Hodges - 1 year ago 64
SQL Question

SQL duplicate persons multiple tables?

I'm trying to write a SQL query that will give me a list of duplicate persons in a database. I can not create a new table with this query.

I'm trying to find where persons have matching first name, last name and dates of birth.

The names are held in a table

persons
and dates of birth are stored in
personsInfo
linked with a matching id.

Answer Source

You should be able to do this with:

select p.id, p.firstName, p.lastName, I.DoB, count(*)
from persons as p
join personsInfo as I
on p.ID = i.PersonsID
group by p.firstname, p.lastName, I.DoB
having count(*) > 1

Found the answer by searching "select duplicates sql" and looking at this question and answer.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download