Finding duplicate entries

  • Does anyone have a script that can find duplicate entries in a table?  Example: 

    Date         Unit        Company_Name

    4/2/05      bu002       ABC Company

    Duplicate entries that were made with the same information entered, but that will search the entire table with other duplicates for other dates, bu's and company names at the same time.

    I do not to run one query at a time.

    If someone could help I would greatly appreciate it.  Thanks

     

     

     

  • Hi do you want to eliminate the duplicates from the table (recommended) or just search for some values and show only one entry rather than duplicate entrys?

    Mike

  • At this point I do not want to eliminate anything, just find all duplicate entries.

  • is this something where a "select distinct" won't do ?! there could be duplicates of any or all fields - or a combination thereof ?! could you provide some more sample data from your table ?!

    hi mike







    **ASCII stupid question, get a stupid ANSI !!!**

  • Date         Unit        Company_Name

    4/2/05      bu002       ABC Company

    11/30/04   bu002       ABC Company

    4/2/05      bu002       ABC Company

    5/12/05    bu002       ABC Company

    11/3004    bu002       ABC Company

    Hope this helps!

     

  • Hi sushila nice to see you. I joined a group hug the other day in the hopes you would show up which you never did so you owe me.

    Mike

  • and your result set should contain:

    Date Unit Company_Name

    4/2/05 bu002 ABC Company

    11/30/04 bu002 ABC Company

    5/12/05 bu002 ABC Company

    is this correct ?!







    **ASCII stupid question, get a stupid ANSI !!!**

  • Yes.

  • ..in that case a "select distinct * from myTable" should give you what you're looking for!

    yes - mike - i do owe you!







    **ASCII stupid question, get a stupid ANSI !!!**

  • if object_id('tempdb..Test') >0

     DROP TABLE Test

    CREATE TABLE Test

    (

    aTime datetime,

    avalue varchar(10), 

    company varchar(20)

    )

    insert into Test values('4/2/05','bu002','ABC Company')

    insert into Test values('11/30/04','bu002','ABC Company')

    insert into Test values('4/2/05','bu002','ABC Company')

    insert into Test values('5/12/05','bu002','ABC Company')

    insert into Test values('11/3/05','bu002','ABC Company')

    SELECT DISTINCT COMPANY

    FROM Test

    -- Returns ABC Company

     

    HTH Mike

     

  • Great but no Haggis

  • no indeed - more like gaggis - yuck!

    it HAS to be the blackbird pie....how quickly you forget!







    **ASCII stupid question, get a stupid ANSI !!!**

  • Thanks, I'll give it a try.

  • ivelisse - let us know how it goes...don't mind us - we're "meeting" after a while hence catching up!







    **ASCII stupid question, get a stupid ANSI !!!**

  • MOI? Forget something you said. I will sing you a song of six pence

    Mike

    But I think you won the bet although there is still a week to go

Viewing 15 posts - 1 through 15 (of 42 total)

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