Click here to Skip to main content
Click here to Skip to main content
Alternative Tip

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

, 2 Sep 2011
Rate this:
Please Sign up or sign in to vote.
Find out the number of duplicates in the table:select count(*), VISTX_ST_FIPS,VISTX_CTY_FIPS,VISTX_TC from TR00.NV_STARTER_INDEXgroup by VISTX_ST_FIPS,VISTX_CTY_FIPS,VISTX_TC having count(*)>1--- Delele them using following statementDELETEFROM TR00.NV_STARTER_INDEXWHERE...

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)

Share

About the Author

Ron sikander

United States United States
No Biography provided

Comments and Discussions

 
Questionphysloc giving Error in Query Pinmembermanoj kumar choubey17-Apr-12 0:46 

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

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Mobile
Web04 | 2.8.140814.1 | Last Updated 2 Sep 2011
Article Copyright 2011 by Ron sikander
Everything else Copyright © CodeProject, 1999-2014
Terms of Service
Layout: fixed | fluid