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
 Deleting duplicates which occur in only one column

Author  Topic 

GavinD1977
Yak Posting Veteran

83 Posts

Posted - 2006-08-09 : 05:26:16
Hello all. I have a table with two coulmns CODE and DESCRITPION. Can anyone suggest how i can go about deleteing the entire record where two or more codes are the same?

Thanks.

chiragkhabaria
Master Smack Fu Yak Hacker

1907 Posts

Posted - 2006-08-09 : 05:39:02
[code]
Delete From Tbl Where Code In
(Select Code from Tbl group by Code having Count(1) >1)
[/code]

Chirag
Go to Top of Page

GavinD1977
Yak Posting Veteran

83 Posts

Posted - 2006-08-09 : 05:52:36
Smashing. Thank you :)
Go to Top of Page

harsh_athalye
Master Smack Fu Yak Hacker

5581 Posts

Posted - 2006-08-09 : 05:54:59
Or this...

Delete from Tbl x 
where exists (select Code from Tbl y where y.Code = x.Code
group by y.Code having count(Code)>1)


Harsh Athalye
India.
"Nothing is Impossible"
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-08-09 : 09:45:33
http://sqlteam.com/forums/topic.asp?TOPIC_ID=6256

Madhivanan

Failing to plan is Planning to fail
Go to Top of Page
   

- Advertisement -