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
 Delete duplicate record

Author  Topic 

asm
Posting Yak Master

140 Posts

Posted - 2006-10-23 : 08:03:09
Hi ,

How can i delete the duplicate record from a table

use Northwind
create table Emp (Ecode char(2), Ename char(10))
Insert into Emp(Ecode, Ename) values('A1','A')
Insert into Emp(Ecode, Ename) values('A1','A')
Insert into Emp(Ecode, Ename) values('A2','B')
Insert into Emp(Ecode, Ename) values('A2','B')
Insert into Emp(Ecode, Ename) values('A3','C')
Insert into Emp(Ecode, Ename) values('A3','C')
Insert into Emp(Ecode, Ename) values('A4','D')
Insert into Emp(Ecode, Ename) values('A4','D')

select * from emp order by Ecode


Thanks

ASM

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-10-23 : 08:04:16
Refer this
http://sqlteam.com/forums/topic.asp?TOPIC_ID=6256

Madhivanan

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

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-10-23 : 08:06:41
[code]SELECT DISTINCT Ecode, Ename INTO #Temp FROM Emp

DELETE FROM Emp

INSERT Emp SELECT Ecode, Ename FROM #Temp

DROP TABLE #Temp[/code]

Peter Larsson
Helsingborg, Sweden
Go to Top of Page

asm
Posting Yak Master

140 Posts

Posted - 2006-10-23 : 08:08:48
There is no primary key..
Go to Top of Page

madhivanan
Premature Yak Congratulator

22864 Posts

Posted - 2006-10-23 : 08:10:19
quote:
Originally posted by asm

There is no primary key..



Did you read the link I posted?

Madhivanan

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

X002548
Not Just a Number

15586 Posts

Posted - 2006-10-23 : 15:03:37
quote:
Originally posted by Peso


INSERT Emp SELECT Ecode, Ename FROM #Temp


Peter Larsson
Helsingborg, Sweden




tsk, tsk, tsk



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2006-10-23 : 15:13:50
INSERT Emp (Ecode, Ename) SELECT Ecode, Ename FROM #Temp

OK?


Peter Larsson
Helsingborg, Sweden
Go to Top of Page

X002548
Not Just a Number

15586 Posts

Posted - 2006-10-24 : 09:42:36
quote:
Originally posted by Peso

INSERT Emp (Ecode, Ename) SELECT Ecode, Ename FROM #Temp

OK?


Peter Larsson
Helsingborg, Sweden



Sure, I was just getting INTO it

Wonder what he means by dups though



Brett

8-)

Hint: Want your questions answered fast? Follow the direction in this link
http://weblogs.sqlteam.com/brettk/archive/2005/05/25/5276.aspx

Add yourself!
http://www.frappr.com/sqlteam



Go to Top of Page
   

- Advertisement -