Saturday, December 28, 2013

How to delete all duplicate records with MIN (Id) and keep Max(Id) record

Yet another solution:



DELETE FROM StockInformation
WHERE Id < (
SELECT MAX(Id)
FROM StockInformation AS csq
WHERE csq.ItemId = StockInformation.ItemId
AND csq.StockTypeUserId = StockInformation.StockTypeUserId
)





Gert-Jan


No comments:

Post a Comment