Click here to Skip to main content
Click here to Skip to main content

How to remove duplicate rows in SQL Server 2008 when no key is present

By , 2 Sep 2011
 

Find out the number of duplicates in the table:

select count(*), VISTX_ST_FIPS,VISTX_CTY_FIPS,VISTX_TC 
from TR00.NV_STARTER_INDEX
group by 
VISTX_ST_FIPS,VISTX_CTY_FIPS,VISTX_TC 
having count(*)>1
 
--- Delele them using following statement
DELETE
FROM  TR00.NV_STARTER_INDEX
WHERE TR00.NV_STARTER_INDEX.%%physloc%%
      NOT IN (SELECT MIN(b.%%physloc%%)
              FROM   TR00.NV_STARTER_INDEX b
              GROUP BY VISTX_ST_FIPS, VISTX_CTY_FIPS, VISTX_TC)

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

About the Author

Ron sikander
United States United States
Member
No Biography provided

Sign Up to vote   Poor Excellent
Add a reason or comment to your vote: x
Votes of 3 or less require a comment

Comments and Discussions

 
You must Sign In to use this message board.
Search this forum  
    Spacing  Noise  Layout  Per page   
Questionphysloc giving Error in Querymembermanoj kumar choubey17 Apr '12 - 0:46 
physloc giving Error in Query

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Permalink | Advertise | Privacy | Mobile
Web02 | 2.6.130516.1 | Last Updated 2 Sep 2011
Article Copyright 2011 by Ron sikander
Everything else Copyright © CodeProject, 1999-2013
Terms of Use
Layout: fixed | fluid