DELETE FROM lots
WHERE id NOT IN
(SELECT DISTINCT max(id)
FROM lots
GROUP BY lotNumber, purchaseNumber);
DELETE FROM lots
WHERE id NOT IN
(SELECT MAX(id)
FROM lots
GROUP BY lotNumber, purchaseNumber);
delete t.*
from t
left join t t1 on t.a = t1.a and t.id > t1.id
where t1.id is not null;