duplicate record - delete [message #550266] |
Sun, 08 April 2012 00:38 |
|
babhuko
Messages: 49 Registered: December 2011 Location: Chennai
|
Member |
|
|
Hi all,
I have a requirement to delete duplicate records. For example,if the below query retrieves count of duplicate records along with the column values.
select col2,col3,col4,col5,col6,col7,count(*) from table
group by
col2,col3,col4,col5,col6,col7
having count(*) > 1;
I would like to retain only one record with max(col1) which is a surrogate key and other records should be deleted.
How to retain one record in a duplicate record set based on max of certain column.
Thanks,
babhuko
|
|
|
|
|
Re: duplicate record - delete [message #550284 is a reply to message #550274] |
Sun, 08 April 2012 01:16 |
|
Michel Cadot
Messages: 68645 Registered: March 2007 Location: Nanterre, France, http://...
|
Senior Member Account Moderator |
|
|
It is useless to repeat what is inside the link Blackswan provided, and even useless when you post less than what has already been provided or when is something wrong:
Are you sure your point 2 delete the duplicates in the meaning OP posted?
You must understand the answer you post before posting it.
By the way, how to do it without using rowid and create table?
Regards
Michel
[Updated on: Sun, 08 April 2012 01:17] Report message to a moderator
|
|
|
|
|
|
|
Re: duplicate record - delete [message #550292 is a reply to message #550289] |
Sun, 08 April 2012 02:04 |
flyboy
Messages: 1903 Registered: November 2006
|
Senior Member |
|
|
@bonvivant: Did you not mistake this thread for the one you started: http://www.orafaq.com/forum/t/180358/0/
Michel gave you logical reason for using ROWID there; maybe you should try to understand it.
Because, the original post in this thread is slightly different - the row is supposed to be "duplicate" if not all columns are the same. So, rows may distinguished by the entire set of columns column instead of ROWID. The question is, what shall be the result when there are multiple "records with max(col1)". Anyway, those rows may be deleted by any method BlackSwan proposed afterwards.
|
|
|
|
|
|
|
|
Re: duplicate record - delete [message #550320 is a reply to message #550319] |
Sun, 08 April 2012 12:14 |
flyboy
Messages: 1903 Registered: November 2006
|
Senior Member |
|
|
Just for completeness: when there will be multiple rows with "max(col1)", this statement will leave all of them (as I stated in my previous post). If you wanted to leave only one (arbitrary) row, you would need to run another DELETE statement in addition - the same one as in the link BlackSwan posted.
|
|
|