SQL Server Forums
Profile | Register | Active Topics | Members | Search | Forum FAQ
 
Register Now and get your question answered!
Username:
Password:
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Displaying duplicates on some fields
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

seekaye
Starting Member

6 Posts

Posted - 11/04/2012 :  05:14:27  Show Profile  Reply with Quote
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

Edited by - seekaye on 11/04/2012 05:21:32

sunitabeck
Flowing Fount of Yak Knowledge

5155 Posts

Posted - 11/04/2012 :  08:59:44  Show Profile  Reply with Quote
SELECT * FROM
(
	SELECT
		*,
		COUNT(*) OVER (PARTITION BY Surname,Forname,Clss) AS N
	FROM
		mytable
)s WHERE N > 1
Go to Top of Page
  Previous Topic Topic Next Topic  
 New Topic  Reply to Topic
 Printer Friendly
Jump To:
SQL Server Forums © 2000-2009 SQLTeam Publishing, LLC Go To Top Of Page
This page was generated in 0.05 seconds. Powered By: Snitz Forums 2000