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
 Development Tools
 ASP.NET
 I want to delete dublicate records

Author  Topic 

balakathiresan
Starting Member

3 Posts

Posted - 2008-11-25 : 07:36:54
i have one table. There are 10 rows all are same records i want to delete dublicate records only ( 9 records).

Any one can help me

Thanks
Balakathiresan

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-11-25 : 07:52:34
DELETE f
FROM (
SELECT ROW_NUMBER() OVER (PARTITION BY col1, col2, ... ORDER BY col1) AS recID
) AS f
WHERE recID > 1



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page

balakathiresan
Starting Member

3 Posts

Posted - 2008-11-26 : 01:49:30
Thanks Peso

In ROW_NUMBER()function not working in sql server 2000. If any another idea tell me

Thanks
Balakathriesan
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-26 : 02:05:58
quote:
Originally posted by balakathiresan

Thanks Peso

In ROW_NUMBER()function not working in sql server 2000. If any another idea tell me

Thanks
Balakathriesan


do you have unique valued column? may be primary key or identity column?
Go to Top of Page

balakathiresan
Starting Member

3 Posts

Posted - 2008-11-26 : 02:18:46
Thanks vikash

I am not set primary key and uni key

empid emmpname occupation salary
1 bala prgr 5000
1 bala prgr 5000
1 bala prgr 5000
1 bala prgr 5000
1 bala prgr 5000
1 bala prgr 5000


Remove duplicate records
i need result as follows

empid emmpname occupation salary
1 bala prgr 5000
Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2008-11-26 : 03:50:05
quote:
Originally posted by balakathiresan

Thanks vikash

I am not set primary key and uni key

empid emmpname occupation salary
1 bala prgr 5000
1 bala prgr 5000
1 bala prgr 5000
1 bala prgr 5000
1 bala prgr 5000
1 bala prgr 5000


Remove duplicate records
i need result as follows

empid emmpname occupation salary
1 bala prgr 5000



SELECT IDENTITY(int,1,1) AS ID,
empid, emmpname, occupation, salary
INTO #Temp
FROM YourTable
--for selection
SELECT empid, emmpname, occupation, salary
FROM
(
SELECT
(SELECT COUNT(*) FROM #Temp WHERE empid =t.empid
AND emmpname=t.emmpname
AND occupation=t.occupation
AND salary=t.salary
AND ID<=t.ID) AS Seq,empid, emmpname, occupation, salary
FROM #Temp t
)r
WHERE Seq>1

--for deletion
DELETE y
FROM YourTable y
LEFT JOIN (
SELECT
(SELECT COUNT(*) FROM #Temp WHERE empid =t.empid
AND emmpname=t.emmpname
AND occupation=t.occupation
AND salary=t.salary
AND ID<=t.ID) AS Seq,empid, emmpname, occupation, salary
FROM #Temp t
)r
ON r.Seq=1
AND r.empid=y.empid
AND r.emmpname=y.emmpname
AND r.occupation=y.occupation
AND r.salary=y.salary
WHERE r.empid IS NULL
Go to Top of Page

onlyforme
Starting Member

25 Posts

Posted - 2008-12-04 : 06:51:04
SELECT row_number() OVER (ORDER BY id) AS slno,* FROM tablename
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2008-12-04 : 07:36:28
See follow-up made 11/26/2008 : 01:49:30



E 12°55'05.63"
N 56°04'39.26"
Go to Top of Page
   

- Advertisement -