Tuesday, March 27, 2012

duplicate rows - how to?

I have first_name field and i want to display duplicated rows only, i mean when the same exact name was there more than one time, like John and John...

Code Snippet

select first_name

from MyTable

groupby first_name

havingcount(*)>1

|||

Try:

select first_name

from dbo.t1

group by first_name

having count(*) > 1

AMB

|||

Using SQL Server 2005,

Code Snippet

;With CTE

as

(

Select First_Name,Row_Number() OVER (Partition By First_Name Order By First_Name) RowId From Table

)

Select Distinct First_Name from CTE Where RowId > 1

No comments:

Post a Comment