it doesn't mean that there are 30 unique records though.
shieldguy
ASKER
actually whats happening while inserting the records in to this table some how the records with same productid and orderid are entering in to the database and so now i need to filter them all out and delete them
do you have a field that uniquely identifies the records in your table (primary key)?
shieldguy
ASKER
returnproductid is the primary key
also if we have 3 records of product id = 33
and orderid = 44
then i need to see all these 3 records with their returnproductid beacuse returnproductid will be uniquie for all 3 of them and so i can delete them
ee_rlee
You can try my last post or change aneeshattingal's solution to:
delete r
from returnproducts r
join
(
select productid, orderid
from tablename
group by productid, orderid
having count(*) > 1
) a on r.productid = a.productid and r.orderid = a.orderid
ee_rlee
This would delete records with duplicate productid and orderid except one (min returnproductid)
DELETE R FROM returnproducts R
WHERE returnproductid<> (SELECT MIN(returnproductid) FROM returnproducts WHERE productID=R.productID and orderID=R.orderID)
from tablename
group by productid, orderid
having count(*) > 1