Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 duplicate rows

Author  Topic 

laddu
Constraint Violating Yak Guru

332 Posts

Posted - 2009-07-07 : 16:56:01
I am new to T-SQL. How to find a only duplicate rows in a table.

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-07-07 : 17:12:13
Using which version of SQL Server?



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

laddu
Constraint Violating Yak Guru

332 Posts

Posted - 2009-07-07 : 17:15:42
SQL Server 2005
Go to Top of Page

SwePeso
Patron Saint of Lost Yaks

30421 Posts

Posted - 2009-07-07 : 17:23:49
SELECT *
FROM (
SELECT *, ROW_NUMBER() OVER (PARTITION BY Col1 ORDER BY Col2) AS recID
) AS d
WHERE recID > 1



N 56°04'39.26"
E 12°55'05.63"
Go to Top of Page

laddu
Constraint Violating Yak Guru

332 Posts

Posted - 2009-07-08 : 12:34:45
Thanks Peso!

Lets say I have a table1

column1 column2

1 a
2 b
3 c
4 a
5 b
6 d

I need a query for below O/P

column1 column2

1 a
4 a
2 b
5 b




Go to Top of Page

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2009-07-08 : 12:40:11
[code]SELECT column1,column2
(
SELECT COUNT(column1 ) OVER (PARTITION BY column2) AS Occurance, column1,column2
FROM YourTable
)t
WHERE Occurance>1
[/code]
Go to Top of Page
   

- Advertisement -