Click here to monitor SSC
SQLServerCentral is supported by Redgate
 
Log in  ::  Register  ::  Not logged in
 
 
 


eliminating duplicates


eliminating duplicates

Author
Message
vish-531091
vish-531091
Grasshopper
Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)

Group: General Forum Members
Points: 16 Visits: 49
Hello All,

i have a table with dupicate records.
I wish to delete the first row among the duplicate records and keep the others Hehe and the other way round.

How should have right the DELETE statement with top 1 clause in it. Crazy

Thanks in Advance..!!
shailesh-519005
shailesh-519005
Valued Member
Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)Valued Member (61 reputation)

Group: General Forum Members
Points: 61 Visits: 216
Hi vish

u have not mentioned which version of sql server u r using because if u are using sql server 2000 then u will not be able to use Delete top clause.
karthik M
karthik M
SSCrazy
SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)

Group: General Forum Members
Points: 2045 Visits: 2582
Simply you can use DISTINCT keyword.

If you give some sample data's you will get lot of help from here.

karthik
karthik M
karthik M
SSCrazy
SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)SSCrazy (2K reputation)

Group: General Forum Members
Points: 2045 Visits: 2582
Say for example,

create table #Emp
(
Eno int,
Ename varchar(5)
)

insert into #Emp
select 1,'AA'
union all
select 1,'AA'
union all
select 2,'BB'
union all
select 3,'CC'

select distinct * into #FinalResult
from #Emp

will give you the expected result.

karthik
John Rowan
John Rowan
SSCarpal Tunnel
SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)SSCarpal Tunnel (4.1K reputation)

Group: General Forum Members
Points: 4072 Visits: 4510
How you do this depends on a couple of factors. How many rows are in your table? How many rows are dupes that need to be deleted?

John Rowan

======================================================
======================================================
Forum Etiquette: How to post data/code on a forum to get the best help - by Jeff Moden
vish-531091
vish-531091
Grasshopper
Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)

Group: General Forum Members
Points: 16 Visits: 49
Hi All,

Let me give my problem description in detail.
I use SQL server 2000.
I have a table 'TAB' with 3 coulumns 'Name','Age','Sex'
and there is no primary key.

I have multiple duplicate data in my table. for eg..

ABC   24   M
ABC   24   M
LMN   27   M
LMN   27   M
LMN   27   M
PQRS   25   F
XYZ   24   M
XYZ   25   M

Now i would wish to 'DELETE' the 1st original row ( Row no 1,3,6,7)
and keep the other duplcates from above data. Cool
Now, If there is a row without any dupicates present.. it will be deleted ( for eg Row no 6)

The condition is i dont want to go for intermediate tables or have any
additional identity column. w00t

Please help..!!

Thanks folks
Sergiy
Sergiy
SSCertifiable
SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)

Group: General Forum Members
Points: 5822 Visits: 11394
vish,
I don't see any numbers assigned to the rows.

How can I tell which ones are 1,3,6,7?
vish-531091
vish-531091
Grasshopper
Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)

Group: General Forum Members
Points: 16 Visits: 49
Hi,
There no row numbers associated.. i just wanted to make it clear..
through that example.

Thanks
Sergiy
Sergiy
SSCertifiable
SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)SSCertifiable (5.8K reputation)

Group: General Forum Members
Points: 5822 Visits: 11394
vish (6/19/2008)i just wanted to make it clear..

You did not succeed.

For me these lines:
LMN 27 M
LMN 27 M
LMN 27 M
look absolutely identical.
If it's all you've go in table they are identical for SQL Server as well.

Open this table in EM and try to remove one of the rows.
I will not do because of "not enough key information".

If you try to delete it from QA you need to specify which row(s) to delete:
DELETE
FROM Table
WHERE ... = 'LMN' AND ... = 27 AND ''' = 'M'
AND ?????

Without specifying what do you mean by ????? all 3 rows will be deleted.
So, you need to define the criteria for the deletion more specifically.
vish-531091
vish-531091
Grasshopper
Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)Grasshopper (16 reputation)

Group: General Forum Members
Points: 16 Visits: 49
hi sergiy,

Thats right..
Those rows are practically identical...
So the point is we need to have some condition which will distinguish them from each other...

So i feel its quite impossible under such given conditions.

I think i get the blackhole.

Thanks to all for your responses..!!
vish Cool
Go


Permissions

You can't post new topics.
You can't post topic replies.
You can't post new polls.
You can't post replies to polls.
You can't edit your own topics.
You can't delete your own topics.
You can't edit other topics.
You can't delete other topics.
You can't edit your own posts.
You can't edit other posts.
You can't delete your own posts.
You can't delete other posts.
You can't post events.
You can't edit your own events.
You can't edit other events.
You can't delete your own events.
You can't delete other events.
You can't send private messages.
You can't send emails.
You can read topics.
You can't vote in polls.
You can't upload attachments.
You can download attachments.
You can't post HTML code.
You can't edit HTML code.
You can't post IFCode.
You can't post JavaScript.
You can post emoticons.
You can't post or upload images.

Select a forum

































































































































































SQLServerCentral


Search