Click here to monitor SSC
SQLServerCentral is supported by Red Gate Software Ltd.
 
Log in  ::  Register  ::  Not logged in
 
 
 
        
Home       Members    Calendar    Who's On


Add to briefcase

how to find duplicated rows in a table Expand / Collapse
Author
Message
Posted Wednesday, June 11, 2008 8:35 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Tuesday, August 19, 2014 3:31 AM
Points: 15, Visits: 289
Comments posted to this topic are about the item how to find duplicated rows in a table
Post #515223
Posted Wednesday, June 18, 2008 12:29 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Friday, July 11, 2014 3:33 PM
Points: 20, Visits: 157
edit: this should be one of the most basic queries ever. so, i have been surprised why you have choosen to add an identity column and querying the table twice with joins, etc.

shouldn't the script below suit your needs?

select y,x
from t1 (NOLOCK)
group by y, x
having count(1) > 1
Post #518771
Posted Wednesday, June 18, 2008 1:41 AM
Forum Newbie

Forum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum NewbieForum Newbie

Group: General Forum Members
Last Login: Friday, April 9, 2010 5:28 AM
Points: 7, Visits: 15
Infact, I didin't understand why you wrote like that code.
Where is the difference from below code.

I think It's very easy.

SELECT * FROM t1 WHERE y IN (
SELECT y FROM t1
GROUP BY y
HAVING COUNT(y)>1
)

Thanks.
Post #518800
Posted Wednesday, June 18, 2008 2:07 AM
SSC-Enthusiastic

SSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-EnthusiasticSSC-Enthusiastic

Group: General Forum Members
Last Login: Thursday, May 29, 2014 12:18 PM
Points: 152, Visits: 95
this has gotta be the most pathetic script i've ever seen...

I'm surprised SSC even published this!!
Post #518810
Posted Wednesday, June 18, 2008 2:51 AM
SSC-Addicted

SSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-AddictedSSC-Addicted

Group: General Forum Members
Last Login: Monday, February 18, 2013 1:11 AM
Points: 478, Visits: 128
WHY???

you can use the following
SELECT
x,
y,
COUNT(y) AS How_Many_Times
FROM t1
GROUP BY x, y
HAVING (COUNT(y) > 1)


I don't understand 1.why do you have to add a rowid!! 2.what is the purpose of adding a third column (z) with a default value of zero!!!

Post #518825
Posted Wednesday, June 18, 2008 6:09 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Wednesday, May 21, 2014 3:47 PM
Points: 15, Visits: 81
ABHILASH DHONGDI (6/18/2008)
this has gotta be the most pathetic script i've ever seen...

I'm surprised SSC even published this!!


My thoughts, exactly. You can pick any line in the article and find problems with it. Awful.
Post #518918
Posted Wednesday, June 18, 2008 8:41 AM
Grasshopper

GrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopperGrasshopper

Group: General Forum Members
Last Login: Sunday, May 4, 2014 2:59 PM
Points: 19, Visits: 149
I would have to agree with the other posts...
this script stinks on ice.

How does this warrant a hyperlink to the "solution script".

Lets keep the quality of the site high....
Fortunately, it usually is



Post #519122
« Prev Topic | Next Topic »

Add to briefcase

Permissions Expand / Collapse