Results 1 to 5 of 5

Thread: Query to remove duplicate

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2006
    Posts
    275

    Query to remove duplicate

    Hi

    I need to design a query that remove all occurance of duplicates.

    Thanks

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Query to remove duplicate

    Thread moved to Database Development forum - which is where SQL questions belong

    Your question makes sense, but is not as clear as we need.. for a start, we need to know what database system you are working with (eg: SQL Server 2005/Oracle 10i/....)

    As you want an SQL statement, we need to know the names of the table and fields, and preferably the data types of the fields too.

    We also need to know what kind of thing you consider to be a duplicate, as there are a couple of common misconceptions about it - it would be useful for you to show us a few example rows of data to help clarify what you want.

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Feb 2006
    Posts
    275

    Re: Query to remove duplicate

    I think this query may be challenging, Be it any DBMS, And talking about fields lets say there is only one field.
    Now as you need to know the datatype of the field, consider both cases in which it is string or varchar
    Or
    The second case is it is Integer or number field.

  4. #4
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Query to remove duplicate

    I didn't ask those questions to be awkward, I asked them because there is information we need to be able to give you a usable answer.. for example, the DBMS involved will have a big effect on what method(s) and syntax are used.

    It is also a bad idea to pretend that the tables have different amount/type of fields to what you are actually dealing with - as the structure often has a serious impact too.

  5. #5
    PowerPoster techgnome's Avatar
    Join Date
    May 2002
    Posts
    34,687

    Re: Query to remove duplicate

    There isn't a blanket generic way of doing this.... for all the reasons si has noted.

    However... the logic behind how to do it is fairly generic - it'll be up to you to figure out how to actually implement it.

    But basically, you take the table, left join it back to itself, on the fields that are potential duplicates - if there's more than 4, then forget it, and use some other means of scrubbing the data - BUT at the same time, joining on where the PKey does NOT MATCH - you DO have a Primary Key on the table, RIGHT - because if they do match, then you've got the same record joining to itself, which isn't what you want. Then in the where, look for NOT NULLS in the joined PKey....that should give you the duplicates.

    Now, do you see why the questions si asked are importaint?

    -tg
    * I don't respond to private (PM) requests for help. It's not conducive to the general learning of others.*
    * I also don't respond to friend requests. Save a few bits and don't bother. I'll just end up rejecting anyways.*
    * How to get EFFECTIVE help: The Hitchhiker's Guide to Getting Help at VBF - Removing eels from your hovercraft *
    * How to Use Parameters * Create Disconnected ADO Recordset Clones * Set your VB6 ActiveX Compatibility * Get rid of those pesky VB Line Numbers * I swear I saved my data, where'd it run off to??? *

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width