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 |
|
js.reddy
Yak Posting Veteran
80 Posts |
Posted - 2008-06-05 : 08:16:33
|
| Hi Guys,I have the following tablecustomerid customername------------------------1 AAA1 AAA2 BBB2 BBB2 BBB3 CCC3 CCCHere, I need to delete duplicate records from the above table.After deleting the duplicate records the table should be like this:customerid customername------------------------1 AAA2 BBB3 CCCCan any one help me!!!!!!Regardsjs.reddy |
|
|
TG
Master Smack Fu Yak Hacker
6065 Posts |
Posted - 2008-06-05 : 08:44:38
|
| check out this topic and associated article:http://www.sqlteam.com/forums/topic.asp?TOPIC_ID=6256And in the future inprove your data integrity and performance by using Primary Keys (and Unique contraints when you have a surrogate key)Be One with the OptimizerTG |
 |
|
|
ayamas
Aged Yak Warrior
552 Posts |
Posted - 2008-06-05 : 09:06:32
|
| Try thisdeclare @tbl table(customerid int,customername varchar(50))insert into @tblselect 1, 'AAA' union allselect 1 ,'AAA' union allselect 2 ,'BBB' union allselect 2 ,'BBB' union allselect 2 ,'BBB' union allselect 3 ,'CCC' union allselect 3 ,'CCC'delete t from(select customerid,customername,row_number()over(partition by customerid,customername order by customerid,customername)as rowidfrom @tbl)t where rowid<>1select * from @tblAnd dont forget what TG said. |
 |
|
|
Vivek.Roberts
Starting Member
1 Post |
Posted - 2008-06-05 : 09:09:03
|
| select distinct column_name into temp_table from duplicate_tabledrop table duplicate_tableselect distinct column_name into duplicate_table from temp_table drop table temp_table |
 |
|
|
|
|
|
|
|