Link to home
Start Free TrialLog in
Avatar of Nana Hemaa
Nana HemaaFlag for United States of America

asked on

SQl Duplicate query in Oracle

How can I accomplish below with SQl  Developer--for Oracle database 11 G


;With CTE As
(Select Cust_ID, name, Results, Date, Row_number() Over(PARTITION  By Cust_ID + Name + Results Order By Date Desc) As Cust
From Customer)
Delete From CTE
Where Cust >1
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Try the correlated sub-query method:
delete from customer c1 where rowid > (select min(rowid) from customer c2 where c1.cust_id=c2.cust_id and c1.results=c2.results);

Open in new window


this deletes everything that has the same cust_id and results.  If more columns define uniqueness, just add them.
try

;With dup as (
Select Cust_ID, name, Results, rowid rid, Date,
       Row_number() Over(PARTITION By Cust_ID, Name, Results Order By Date Desc) as rn
  From Customer
)
Delete From Customer
 Where rowid in (select rid fom dup where rn>1)

Open in new window

Huseyin,

Have you tried a delete using CTE in Oracle?
ASKER CERTIFIED SOLUTION
Avatar of slightwv (䄆 Netminder)
slightwv (䄆 Netminder)

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial