I've got the following code running in a procedure, called by a KSH script. It does what it needs to do (delete dup records), but it takes a long time to complete. I realize there's some redundancy here, but I can't seem to get it to work any other way I've tried. I would appreciate help in tightening up the code:
Code:
PROCEDURE Delete_Dups IS
BEGIN
DELETE FROM Equipment
WHERE Sequence NOT IN
(
SELECT MAX(Sequence)
FROM Equipment e1
WHERE e1.CustID||SerialNo = CustID||SerialNo
GROUP BY CustID||SerialNo
HAVING COUNT(*) > 1
)
and
CustID||SerialNo IN
(
SELECT CustID||SerialNO
FROM Equipment e1
GROUP BY CustID||SerialNo
HAVING COUNT(*) > 1
);
commit;
END Delete_Dups;