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
 SQL delete statement

Author  Topic 

berengar
Starting Member

21 Posts

Posted - 2006-10-02 : 07:05:48
Hi what do i need to add to this stmt to delete the result ?
---------------
select ct_cust1_text01,ct_address,ct_cust1_text09,count(*)from TABLE_NAME group by ct_cust1_text01,ct_address,ct_cust1_text09 having count(*) > 1
---------

i have tried delete * from TABLE_NAME where (select...)

not great at SQL appreciate any help...

khtan
In (Som, Ni, Yak)

17689 Posts

Posted - 2006-10-02 : 08:01:33
[code]delete d
from TABLE_NAME d inner join
(
select ct_cust1_text01, ct_address, ct_cust1_text09, count(*) as cnt
from TABLE_NAME
group by ct_cust1_text01,ct_address,ct_cust1_text09
having count(*) > 1
) t
ON d.ct_cust1_text01 = t.ct_cust1_text01
AND d.ct_address = t.ct_address
AND d.ct_cust1_text09 = t.ct_cust1_text09
[/code]



KH

Go to Top of Page

Kristen
Test

22859 Posts

Posted - 2006-10-02 : 08:59:17
Errmmm ... you're not trying to delete the duplicates and leave one record behind are you?

Kristen
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-10-02 : 09:34:28

http://sqlteam.com/forums/topic.asp?TOPIC_ID=6256

Madhivanan

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

- Advertisement -