How do you find duplicate entries in a SQL table

  • Hi,

    while I don't yet have any code to show I am trying to find duplicates in a table.  So I revert to excel logic here in that if I were working in that however many columns I had, I would take the values from every cell in a row and I would concatenate to produce a unique value.  Then I would identify duplicates.  How do you do this in SQL?  Having count >1 is part of it but how do you ensure the check is done on a unique concatenation of values

     

    Thanks!

  • If I have a table:

    CREATE TABLE EMP
    (
    ID int
    , NAME varchar(50)
    , TITLE varchar (20)
    );
    GO
    INSERT INTO EMP
    VALUES
    (1, 'Joe Cool', 'CEO')
    , (1, 'Joe Cool', 'CEO')
    . (2. . 'Snoopy', .'pet');
    GO
    SELECT ID, NAME, TITLE
    FROM EMP
    GROUP BY ID, NAME, TITLE
    HAVING COUNT(*)>1;

Viewing 2 posts - 1 through 1 (of 1 total)

You must be logged in to reply to this topic. Login to reply