Displaying duplicate entries.

  • Hi,

    Please let me know how to find out or display only the duplicate entries in table.

    Thanks in advance

  • Hi

    To find duplicate ( or even more than duplicates ) try this

    select

    field1,

    field2,

    count(*)

    from table

    group by

    field1,

    field2

    having count(*)>1

    where field1, field2 are the fields that will be checked for duplicates.

  • Hi,

    in Nutshell use the below query to find out the duplicate records.

    SELECT

    list_of_all_columns

    FROM

    tablename

    GROUP BY

    list_of_all_columns

    HAVING

    count(*) > 1

    Thanks -- Vj

    http://dotnetvj.blogspot.com

  • Create table tb_MyTest (n_RecordID int identity(1,1) , s_Name Varchar(20) )

    Insert into tb_MyTest(s_Name) Select 'Namha'

    Insert into tb_MyTest(s_Name) Select 'Shadique'

    Insert into tb_MyTest(s_Name) Select 'Jamil'

    Insert into tb_MyTest(s_Name) Select 'Begum Kubra'

    Insert into tb_MyTest(s_Name) Select 'Namha'

    Insert into tb_MyTest(s_Name) Select 'Namha'

    Insert into tb_MyTest(s_Name) Select 'Begum Kubra'

    Insert into tb_MyTest(s_Name) Select 'Shakeel'

    /*Find Duplicate Reports*/

    Select count(1), s_Name from tb_MyTest

    group by s_Name

    Having Count(1)>1

    /*Another Way to find Duplicate Rerords in Table*/

    Select s_Name

    FROM tb_MyTest

    WHERE n_RecordID NOT IN

    (

    SELECT MAX(n_RecordID)

    FROM tb_MyTest

    GROUP BY s_Name

    )

    Naseem Akhtar

  • Create table tb_MyTest (n_RecordID int identity(1,1) , s_Name Varchar(20) )

    Insert into tb_MyTest(s_Name) Select 'Namha'

    Insert into tb_MyTest(s_Name) Select 'Shadique'

    Insert into tb_MyTest(s_Name) Select 'Jamil'

    Insert into tb_MyTest(s_Name) Select 'Begum Kubra'

    Insert into tb_MyTest(s_Name) Select 'Namha'

    Insert into tb_MyTest(s_Name) Select 'Namha'

    Insert into tb_MyTest(s_Name) Select 'Begum Kubra'

    Insert into tb_MyTest(s_Name) Select 'Shakeel'

    /*Find Duplicate Reports*/

    Select count(1), s_Name from tb_MyTest

    group by s_Name

    Having Count(1)>1

    /*Another Way to find Duplicate Rerords in Table*/

    Select s_Name

    FROM tb_MyTest

    WHERE n_RecordID NOT IN

    (

    SELECT MAX(n_RecordID)

    FROM tb_MyTest

    GROUP BY s_Name

    )

    Naseem Akhtar

  • Create table tb_MyTest (n_RecordID int identity(1,1) , s_Name Varchar(20) )

    Insert into tb_MyTest(s_Name) Select 'Namha'

    Insert into tb_MyTest(s_Name) Select 'Shadique'

    Insert into tb_MyTest(s_Name) Select 'Jamil'

    Insert into tb_MyTest(s_Name) Select 'Begum Kubra'

    Insert into tb_MyTest(s_Name) Select 'Namha'

    Insert into tb_MyTest(s_Name) Select 'Namha'

    Insert into tb_MyTest(s_Name) Select 'Begum Kubra'

    Insert into tb_MyTest(s_Name) Select 'Shakeel'

    /*Find Duplicate Reports*/

    Select count(1), s_Name from tb_MyTest

    group by s_Name

    Having Count(1)>1

    /*Another Way to find Duplicate Rerords in Table*/

    Select s_Name

    FROM tb_MyTest

    WHERE n_RecordID NOT IN

    (

    SELECT MAX(n_RecordID)

    FROM tb_MyTest

    GROUP BY s_Name

    )

    Naseem Akhtar

Viewing 6 posts - 1 through 5 (of 5 total)

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