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
 Displaying duplicates on some fields

Author  Topic 

seekaye
Starting Member

6 Posts

Posted - 2012-11-04 : 05:14:27
Hi


My table looks like this:


Surname Forename Clss Colour
Anna Archibald A Green
Anna Archibald A Blue
Anna Archibald B Red
Bill Blackman A Red
Bill Blackman B Green
Chris Cardman C Green
Chris CardMan C Blue



I want to return all the records where a person is in the same class
e.g.


Anna Archibald A Green
Anna Archibald A Blue
Chris Cardman C Green
Chris CardMan C Blue

I've got as far as

SELECT surname,forename,class
FROM mytable
GROUP BY surname,forename having count(*) > 1

which returns

Anna Archibald C
Chris CardMan C

Thanks for any help

sunitabeck
Master Smack Fu Yak Hacker

5155 Posts

Posted - 2012-11-04 : 08:59:44
[code]SELECT * FROM
(
SELECT
*,
COUNT(*) OVER (PARTITION BY Surname,Forname,Clss) AS N
FROM
mytable
)s WHERE N > 1[/code]
Go to Top of Page
   

- Advertisement -