how to find out duplicate entries?

  • Hi

    How do i find out if there are any duplicate entries in a table?

    Thanks in advance

    Vij

     

  • You could do something like this:

    SELECT field

    FROM table

    GROUP BY field

    HAVING COUNT(field) > 1

  • select column1, column2,column3,column4,column5,column6 from tblone where column1 in

    (select column1 from tblone

    group by column1

    having count(column1) > 1)

    and

    column5 in (select column5 from tblone

    group by column5

    having count(column5) > 1)

    order by column1, column2 asc

    In my case if an entry has a different column5 it doesn't count as a duplicate.  Please note that this is a brute force method and not necessarily the most efficient. 

     


    Kindest Regards,

    Scott Beckstead

    "We cannot defend freedom abroad by abandoning it here at home!"
    Edward R. Murrow

    scottbeckstead.com

  • another solution:

     

    SELECT     field, COUNT(*) AS cnt

    FROM         dbo.table

    GROUP BY field

    HAVING      (COUNT(*) > 1)

     

    this will displays the field duplicated and how many is duplicated.

    In Theory, theory and practice are the same...In practice, they are not.

Viewing 4 posts - 1 through 3 (of 3 total)

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