Click here to Skip to main content
11,487,721 members (72,988 online)
Click here to Skip to main content

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

, 2 Sep 2011 CPOL 8.3K 1
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 Pin
manoj kumar choubey17-Apr-12 1:46
membermanoj kumar choubey17-Apr-12 1: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 | Terms of Use | Mobile
Web04 | 2.8.150520.1 | Last Updated 2 Sep 2011
Article Copyright 2011 by Ron sikander
Everything else Copyright © CodeProject, 1999-2015
Layout: fixed | fluid