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.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 How to remove the duplicated rows

Author  Topic 

goligol
Posting Yak Master

128 Posts

Posted - 2011-12-05 : 17:06:53
I have a table that most of the rows are duplicated:

hts_code naics8_02 ust_code district port port_district fips
0101100010 11292000 3330 52 06 5206 12025
0101100010 11292000 3330 52 06 5206 12025
0101100010 11292000 4120 52 06 5206 12025
0101100010 11292000 4120 52 06 5206 12025
0101100010 11292000 4231 52 06 5206 12025
0101100010 11292000 4231 52 06 5206 12025

How I can only keep one?
thx

consultor.dwh
Starting Member

6 Posts

Posted - 2011-12-05 : 17:21:28
select distinct *
from table
Go to Top of Page

mmarovic
Aged Yak Warrior

518 Posts

Posted - 2011-12-05 : 18:55:53
[code]select distinct *
into new_table
from existing_table;

exec sp_rename 'existing_table' 'temp_name' --just in case
exec sp_rename 'new_table' existing_table
go[/code]
if everything goes well you can dropt table temp_name


Mirko

My blog: http://mirko-marovic-eng.blogspot.com/
Go to Top of Page
   

- Advertisement -