Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
| Author |
Topic |
|
cplusplus
Aged Yak Warrior
567 Posts |
Posted - 2008-08-07 : 11:33:25
|
| For some reason due to a bug on my frontend app, it created many duplicate rows, now want to delete those rows based on englishdescription (field), if more than 1 row with same englishdescription exists then keep one row and delete the rest.delete TAB_Netorders where orderkey='lblsubject' and checking englishdescription if more than 1 row delete them.Thank you very much for the helpful information. |
|
|
Vinnie881
Master Smack Fu Yak Hacker
1231 Posts |
Posted - 2008-08-07 : 11:54:08
|
As long as you have a ID column for the row you can do thisselect Row_Number() over (Partition by a.EnglishDescription Order by a.MyID) as RowNo,a.MyIDinto #TmpTAB_Netorders adelete afromTab_NetOrders ainner Join#Tmp bon a.MyID = b.MyIDwhere b.RowNo > 1 |
 |
|
|
cplusplus
Aged Yak Warrior
567 Posts |
Posted - 2008-08-07 : 12:30:21
|
Hello Vinnie881,I used the following based on your exapmple: getting error incorrect syntax a:**********************select Row_Number() over (Partition by a.EnglishDescription Order by a.TextID) as RowNo,a.TextIDinto #TmpTAB_ccsNetPickLists a where a.fieldlabelkey='lblsubject' ---- here on this linedelete afromTAB_ccsNetPickLists ainner Join#Tmp bon a.TextID = b.TextIDwhere b.RowNo > 1 Thank you very much. |
 |
|
|
Vinnie881
Master Smack Fu Yak Hacker
1231 Posts |
Posted - 2008-08-07 : 12:31:39
|
| my bad..select Row_Number() over (Partition by a.EnglishDescription Order by a.TextID) as RowNo,a.TextIDinto #TmpfromTAB_ccsNetPickLists a where a.fieldlabelkey='lblsubject' ---- here on this linedelete afromTAB_ccsNetPickLists ainner Join#Tmp bon a.TextID = b.TextIDwhere b.RowNo > 1 |
 |
|
|
|
|
|