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 |
|
chiragkhabaria
Master Smack Fu Yak Hacker
1907 Posts |
Posted - 2005-08-28 : 08:47:19
|
| Hi All,In My table i have records which are duplicate. i run the following query Select EmpID,Count(1) From Employee Group By EmpID Having Count(1) >1 There were many duplicate empid , so i want remove them..for eg. EmpId Count1044 2353 21059 2368 215 2338 2691 2383 2308 230 21014 2323 2676 2751 2398 245 21029 2428 2263 2781 21119 2i want to delete only one occurance of this empID. if they are more then one number of time i should be able delete all the rest of them keeping only one occurance so finally my result should come like this when i run above mentioned query.EmpId Count1044 1353 11059 1368 115 1338 1691 1383 1308 130 11014 1323 1676 1751 1398 145 11029 1428 1263 1781 11119 1ThanksComplicated things can be done by simple thinking |
|
|
kapilarya
Yak Posting Veteran
86 Posts |
Posted - 2005-08-28 : 10:02:02
|
| there will be some unique key in the table. and if there is then try to apply this:Begin trandelete * from employee u1where u1.uniquekey <> (select max(uniquekey) from employee u2 where u2.empid = u1.empid) Select EmpID,Count(1) From Employee Group By EmpID Having Count(1) >1Rollback tranKapil Arya |
 |
|
|
|
|
|