Find duplicates in SQL

前端 未结 2 1937
说谎
说谎 2020-12-16 18:29

I have a large table with the following data on users.

social security number
name
address

I want to find all possible duplicates in the ta

2条回答
  •  离开以前
    2020-12-16 19:21

    A grouping on SSN should do it

    SELECT
       ssn
    FROM
       Table t1
    GROUP BY
       ssn
    HAVING COUNT(*) > 1
    

    ..or if you have many rows per ssn and only want to find duplicate names)

    ...
    HAVING COUNT(DISTINCT name) > 1 
    

    Edit, oops, misunderstood

    SELECT
       ssn
    FROM
       Table t1
    GROUP BY
       ssn
    HAVING MIN(name) <> MAX(name)
    

提交回复
热议问题