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 |
|
objkiran
Starting Member
11 Posts |
Posted - 2005-01-24 : 10:07:10
|
| i have a table, no primary key so the table has duplicate records for same identifier. I need to leave one record and delete the duplicate records .can some one help me. |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2005-01-24 : 10:12:22
|
| Full duplicates?pick the column or columns which sould form the primary key andset rowcount 1select 1while @@rowcount > 0delete tblfrom tbl t1join (select pk1, pk2 from tbl group by pk1, pk2 having count(*) > 1) t2on t1.pk1 = t2.pk1and t1.pk2 = t2.pk2set rowcount 0==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
spirit1
Cybernetic Yak Master
11752 Posts |
Posted - 2005-01-24 : 10:12:31
|
select * from (select * from MyTableunion select * from MyTable) tGo with the flow & have fun! Else fight the flow |
 |
|
|
objkiran
Starting Member
11 Posts |
Posted - 2005-01-24 : 10:31:03
|
| hello nr,the query which you gave me deletes all the duplicate records. but my goal is to leave one record and delete other for a id. |
 |
|
|
nr
SQLTeam MVY
12543 Posts |
Posted - 2005-01-24 : 11:22:31
|
| Does it? It should leave one version of each duplicate row.Of course it's always possible I've made a mistake.==========================================Cursors are useful if you don't know sql.DTS can be used in a similar way.Beer is not cold and it isn't fizzy. |
 |
|
|
|
|
|