Greens8301
asked on
how to delete duplicate rows in table sql server 2005
I have 6 identical rows of 4 columns table in sql server 2005
I like to have a script to delete the duplicate rows
Is there a way to list rowid ( oracle concept) along with the columns to delete one of the duplicate rows
Thanks
I like to have a script to delete the duplicate rows
Is there a way to list rowid ( oracle concept) along with the columns to delete one of the duplicate rows
Thanks
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Delete from MyTable where ID Not IN
(
select max(ID) from MyTable Group By Duplicate Colum1, Duplicate Column2,Duplicate Column 3
)
Table must have identity column which would identify the duplicate records. Here in MyTable ID as identity column and duplicate columns are duplicate columns 1,2 & 3 (very obvious to know...!!!)
Also refer : http://support.microsoft.c om/kb/1394 44
(
select max(ID) from MyTable Group By Duplicate Colum1, Duplicate Column2,Duplicate Column 3
)
Table must have identity column which would identify the duplicate records. Here in MyTable ID as identity column and duplicate columns are duplicate columns 1,2 & 3 (very obvious to know...!!!)
Also refer : http://support.microsoft.c
http://msdn.microsoft.com/en-us/library/ms186734(SQL.90).aspx
http://msdn.microsoft.com/en-us/library/ms186734(SQL.90).aspx
if you RANK them just in the "partition by" field list ALL the fields then delete where Rank is <> '1'
Similar for Row