Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations MikeeOK on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

delete all but oldest duplicate

Status
Not open for further replies.

EchoAlertcom

IS-IT--Management
Oct 8, 2002
239
US

Hello.

Do I have this statement correct if I want to delete all but the oldest of duplicate records?

Code:
delete from dbo.customers
where dbo.customers.UID != 
		(Select MIN(UID) from dbo.customers adb
			where adb.emailaddr = dbo.customers.emailaddr)

Thank you,
Steve
 
Its tough to tell you the data you want to delete is correct or not.
Try the below script audit few records thats the data you want to delete. Backup the table some where prior to that


Select *
from dbo.customers
where dbo.customers.UID !=
(Select MIN(UID) from dbo.customers adb
where adb.emailaddr = dbo.customers.emailaddr)


Dr.Sql
Good Luck.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top