DBAsupport.com Forums - Powered by vBulletin
Results 1 to 3 of 3

Thread: Removing duplicates

  1. #1
    Join Date
    Jul 2000
    Posts
    70
    How can I remove duplicates from a table.
    Say I have a table of phonenumbers and status as columns and the key is on both.
    I have entries in the table that have the same phonenumber but different status values for a certain reason.
    Now I want to get rid of the duplicate phonenumbers.
    What sql statement will help me achive that?
    Thanks.

  2. #2
    Join Date
    Aug 2000
    Location
    Ny
    Posts
    105
    DELETE FROM MY_TABLE A
    WHERE A.ROWID <
    (SELECT MAX(B.ROWID)
    FROM MY_TABLE B
    WHERE A.PHONENUMBER = B.PHONENUMBER);

  3. #3
    Join Date
    Jun 2000
    Location
    Conway,AR,USA
    Posts
    29
    Best thing is
    CREATE table phone_dedup AS
    (SELECT a.phone_number,
    a.status
    FROM (SELECT rowid,
    phone_number,
    status
    FROM phone_info b
    WHERE b.rowid = (SELECT max(rowid)
    FROM phone_info b
    WHERE b.phone_number = a.phone_number
    AND b.status = a.status)))
    /


    Soumya
    still learning

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