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
 Distinct record equal to 2 values from same column
 New Topic  Reply to Topic
 Printer Friendly
Author Previous Topic Topic Next Topic  

daddyjmo
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

daddyjmo
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

visakh16
Very Important crosS Applying yaK Herder

India
52249 Posts

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

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


------------------------------------------------------------------------------------------------------
SQL Server MVP
http://visakhm.blogspot.com/
https://www.facebook.com/VmBlogs
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.08 seconds. Powered By: Snitz Forums 2000