aspose file tools
The moose likes Oracle/OAS and the fly likes delete duplicate rows Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Products » Oracle/OAS
Reply Bookmark "delete duplicate rows" Watch "delete duplicate rows" New topic
Author

delete duplicate rows

sumeet mittal
Greenhorn

Joined: Dec 22, 2001
Posts: 4
What's the query for identifying and deleting duplicate rows in a table.
For eg if i have 10 similar rows in a table,then to identify them and deleting 9 rows out of 10.
Thanks in advance
Sumeet Mittal
Beksy Kurian
Ranch Hand

Joined: Jul 11, 2001
Posts: 254
try this
delete from testtable a
where exists
(select 1 from testtable b
where b.dup_value = a.dup_value
and b.rowid > a.rowid)
Regards
Beksy
Michael Matola
whippersnapper
Ranch Hand

Joined: Mar 25, 2001
Posts: 1675
Detecting duplicates
I'll show you two of the most useful SQL queries you'll ever learn. (Shh! Don't tell everybody!)
First assume a table with the following data. (No key fields.)

To find duplicates, use the following query.

To use this query in the more general case, just modify the list of fields in the GROUP BY clause (giving careful thought to key vs. nonkey fields and how you're defining a "duplicate").
To see the entire row for each of these "duplicates," just nest the above query:

For our present data, this query isn't particularly interesting because our table only has 1 field. It becomes more useful when you're dealing with rows that match on some fields but not others.
Deleting duplicates
Another way of "deleting" duplicates is to insert into a temp table, then rename the table.

Give careful thought to what fields are in the select (distinct) list because it will affect what's considered a duplicate.
 
 
subject: delete duplicate rows
 
Threads others viewed
How can i delete the duplicate values in a table
deleting more than one rows sql
regarding JTable scrollabrs
duplicate rows in table
How to delete duplicate rows
WebSphere development made easy
without the weight of IBM tools
http://www.myeclipseide.com