Saturday, August 6, 2011

Delete dupplicate rows from a table when there is no primary key

Suppose we have a table tblStock with field StcokID which has following values:
GOOG
BA
GOOG
YAHOO
GOOG


Following query can be used to remove duplicate rows in this case:


DELETE TOP (SELECT COUNT(*) -1 FROM tblStock WHERE StockID = 'GOOG')
FROM tblStock  WHERE StockID = 'GOOG'

No comments:

Post a Comment

If you’re using Visual Studio to build your .NET MAUI app on a Mac, locating the IPA (iOS App Package) file can be a bit tricky

  If you’re using   Visual Studio   to build your   .NET MAUI   app on a   Mac , locating the   IPA (iOS App Package)   file can be a bit tr...