🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.databases.ms-sqlserver
Article #28

Re: - Delete Multiple Rows?

#28
From: Louis Davidson
Date: Thu, 31 Oct 1996 00:00
53 lines
2191 bytes
Try 	select		col1,
			count(*)
	into 		#hold
 	from		myTable
 	group by	col1
 	having 		count(*) > 1

delete	myTable
from	myTable, #hold
where	myTable.col1 = #hold.col1

The only problem is that this will delete both rows. There are better
solutions that will not, if you want I could go through them. 

-- 
----------------------------------------------------------------------------
------------
Louis Davidson
Christian Broadcasting Network

work: louis.davidson@cbn.org
home: vallou@infi.net
virtual address: http://members.aol.com/vallou

"I used to think anyone doing anything weird was weird.
I suddenly realized that anyone doing anything weird wasn't 
weird at all and that it was the people saying they were weird 
that were weird."
Paul McCartney
----------------------------------------------------------------------------
------------

Les Gainous <lesgainous@earthlink.net> wrote in article
<3276F4A7.1842@earthlink.net>...
> I'm using MS-SQL Server 6.5 (but any generic SQL syntax would be
> appreciated):
> 
> How can I delete multiple occurrences of a row within a table. I know
> how to display the rows which are duplicated:
> 
> 	select		col1,
> 			count(*)
> 	from		myTable
> 	group by	col1
> 	having 		count(*) > 1
> 
> But now that I have that listing, how can I delete the second (or third,
> or...) occurrence of the row--preserving the first occurrence.
> 
> Thanks in advance!
> Les
> 
Technical Details
Message-ID: <01bbc734$69c95690$79431a9f@louman-s-home>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <3276F4A7.1842@earthlink.net>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f6611,e42b60ff2edc4f24
X-Google-Attributes: gidf6611,public
X-Google-Thread: f4bf8,e42b60ff2edc4f24
X-Google-Attributes: gidf4bf8,public
X-Google-Thread: 104de1,e42b60ff2edc4f24
X-Google-Attributes: gid104de1,public
X-Google-Thread: 11301e,e42b60ff2edc4f24
X-Google-Attributes: gid11301e,public
From: "Louis Davidson" <vallou@infi.net>
Subject: Re: - Delete Multiple Rows?
Date: 1996/10/31
Message-ID: <01bbc734$69c95690$79431a9f@louman-s-home>
X-Deja-AN: 193417032
references: <3276F4A7.1842@earthlink.net>
organization: CBN
newsgroups: comp.databases.ms-sqlserver,comp.databases.theory,bit.databases.mssql-l,microsoft.public.sqlserver.programming