Querying SQL table with different values in same column with same ID

前端 未结 2 1838
逝去的感伤
逝去的感伤 2021-01-29 10:25

I have an SQL Server 2012 table with ID, First Name and Last name. The ID is unique per person but due to an error in the historical feed,

相关标签:
2条回答
  • 2021-01-29 10:47
    SELECT *
    FROM myTable
    WHERE ID IN (
          SELECT ID
          FROM myTable
          GROUP BY ID
          HAVING MAX(LastName) <> MIN(LastName) OR MAX(FirstName) <> MIN(FirstName) 
          )
    ORDER BY ID, LASTNAME
    
    0 讨论(0)
  • 2021-01-29 10:54
    SELECT
        ID
    FROM
        <<Table>>
    GROUP BY
        ID
    HAVING
        COUNT(*) > 1;
    
    0 讨论(0)
提交回复
热议问题