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

Open default email app in .NET MAUI

Sample Code:  if (Email.Default.IsComposeSupported) {     string subject = "Hello!";     string body = "Excellent!";    ...