posted 16 years ago
i've an APR_MGR table with columns as mgr_id, flag, and backupid. thr is no primary key constraints in the table. the data is like below:
MgrID flag backupid
101 N null
101 N null
101 N null
102 Y 1111
103 Y 2222
now, i wud like to write a delete query, that will delete all the duplicate records of MgrID 101, except the first one.
i've written the below query:
delete from APR_MGR where MgrID = 101 and flag = 'N' and 1 < (select count(MgrID) from APR_MGR where MgrID = 101 and flag = 'N')
i was expecting 2 records to be deleted of MgrID 101, but it deleted all the 3 records.
what shall be the correct query?
[ August 30, 2008: Message edited by: vikas sharmaa ]