-
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.
-
DELETE FROM MY_TABLE A
WHERE A.ROWID <
(SELECT MAX(B.ROWID)
FROM MY_TABLE B
WHERE A.PHONENUMBER = B.PHONENUMBER);
-
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|