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

Our new SQL Server Forums are live! Come on over! We've restricted the ability to create new threads on these forums.

SQL Server Forums
Profile | Active Topics | Members | Search | Forum FAQ
Save Password
Forgot your Password?

 All Forums
 General SQL Server Forums
 New to SQL Server Programming
 Distinct record equal to 2 values from same column
 Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

Starting Member

2 Posts

Posted - 12/06/2013 :  14:41:29  Show Profile  Reply with Quote
Distinct name that match both subjects (math, science) from classname in level 2 only. Not sure where to even start. Any help is greatly appreciated! Sorry for the crude example table below:

name subject level
bob math 2
hank math 1
joe science 2
bob science 2
joe math 2
ben science 2
carl science 1

Starting Member

2 Posts

Posted - 12/06/2013 :  14:43:02  Show Profile  Reply with Quote
So basically return set should return bob and joe because they both have math and science at level 2 only.
Go to Top of Page

Very Important crosS Applying yaK Herder

52326 Posts

Posted - 12/07/2013 :  08:22:04  Show Profile  Reply with Quote

FROM table
HAVING COUNT(DISTINCT CASE WHEN subject IN ('math','science') AND level = 2 THEN subject END) =2

SQL Server MVP
Go to Top of Page
  Previous Topic Topic Next 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.02 seconds. Powered By: Snitz Forums 2000