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
 Query..bringing back all data elements

Author  Topic 

boehnc
Starting Member

15 Posts

Posted - 2011-07-22 : 12:55:51
Newbie obviously. Here's a simple dataset in my table:

Student Date Grade

1 04/11 A
1 03/11 B
2 04/11 A
2 05/11 B
2 06 11 B
3 03/11 C
3 04/11 A

I want to filter on all those students who got "B's"...but I want to bring back all tests for those students. So when I filter for B, I want it to bring back all of Student 1 and 2's test grades, includeing the A's...best option? Any help is appreciated.

visakh16
Very Important crosS Applying yaK Herder

52326 Posts

Posted - 2011-07-22 : 13:01:36
[code]
SELECT t.*
FROM Table t
INNER JOIN (SELECT Student FROM Table GROUP BY Student HAVING SUM(CASE WHEN Grade='B' THEN 1 ELSE 0 END) > 0 ) t1
ON t1.Student = t.Student
[/code]

------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/

Go to Top of Page
   

- Advertisement -