Saturday, December 28, 2013

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

Simply add an extra condition then:



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





For every expert, there is an equal and opposite expert. - Becker's Law





My blog




My TechNet articles


No comments:

Post a Comment