>SELECT Accountno As Account_No,COUNT( * ) AS DupCount; > FROM New_master ; > INTO CURSOR Duplicates ; > GROUP BY Accountno ; > HAVING DupCount > 1 >>
delete NM from New_Master NM ; where exists (select 1 from (SELECT Accountno As Account_No,COUNT( * ) AS DupCount, MAX(AccountDate) as LastDate ; FROM New_master ; GROUP BY Accountno ; HAVING DupCount > 1) X where X.Account_No = NM.AccountNo and NM.AccountDate < X.LastDate)