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.
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 meThanksBalakathiresan |
|
SwePeso
Patron Saint of Lost Yaks
30421 Posts |
Posted - 2008-11-25 : 07:52:34
|
DELETE fFROM (SELECT ROW_NUMBER() OVER (PARTITION BY col1, col2, ... ORDER BY col1) AS recID) AS fWHERE recID > 1 E 12°55'05.63"N 56°04'39.26" |
|
|
balakathiresan
Starting Member
3 Posts |
Posted - 2008-11-26 : 01:49:30
|
Thanks PesoIn ROW_NUMBER()function not working in sql server 2000. If any another idea tell meThanksBalakathriesan |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-26 : 02:05:58
|
quote: Originally posted by balakathiresan Thanks PesoIn ROW_NUMBER()function not working in sql server 2000. If any another idea tell meThanksBalakathriesan
do you have unique valued column? may be primary key or identity column? |
|
|
balakathiresan
Starting Member
3 Posts |
Posted - 2008-11-26 : 02:18:46
|
Thanks vikashI am not set primary key and uni keyempid emmpname occupation salary1 bala prgr 50001 bala prgr 50001 bala prgr 50001 bala prgr 50001 bala prgr 50001 bala prgr 5000Remove duplicate recordsi need result as followsempid emmpname occupation salary1 bala prgr 5000 |
|
|
visakh16
Very Important crosS Applying yaK Herder
52326 Posts |
Posted - 2008-11-26 : 03:50:05
|
quote: Originally posted by balakathiresan Thanks vikashI am not set primary key and uni keyempid emmpname occupation salary1 bala prgr 50001 bala prgr 50001 bala prgr 50001 bala prgr 50001 bala prgr 50001 bala prgr 5000Remove duplicate recordsi need result as followsempid emmpname occupation salary1 bala prgr 5000
SELECT IDENTITY(int,1,1) AS ID,empid, emmpname, occupation, salaryINTO #TempFROM YourTable--for selectionSELECT empid, emmpname, occupation, salaryFROM(SELECT(SELECT COUNT(*) FROM #Temp WHERE empid =t.empidAND emmpname=t.emmpnameAND occupation=t.occupationAND salary=t.salaryAND ID<=t.ID) AS Seq,empid, emmpname, occupation, salaryFROM #Temp t)rWHERE Seq>1--for deletionDELETE yFROM YourTable yLEFT JOIN (SELECT(SELECT COUNT(*) FROM #Temp WHERE empid =t.empidAND emmpname=t.emmpnameAND occupation=t.occupationAND salary=t.salaryAND ID<=t.ID) AS Seq,empid, emmpname, occupation, salaryFROM #Temp t)rON r.Seq=1AND r.empid=y.empidAND r.emmpname=y.emmpnameAND r.occupation=y.occupationAND r.salary=y.salaryWHERE r.empid IS NULL |
|
|
onlyforme
Starting Member
25 Posts |
Posted - 2008-12-04 : 06:51:04
|
SELECT row_number() OVER (ORDER BY id) AS slno,* FROM tablename |
|
|
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" |
|
|
|
|
|
|
|