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.
Author |
Topic |
ahjeck
Starting Member
6 Posts |
Posted - 2010-10-25 : 16:31:47
|
Hi, I am having trouble generating a query. The query I want is the following:Query all students who does not have both the 'Interview' AND 'FallApp' category.This Student Call table has records based on the amount of times they call in for either an interview or a fall application review. Calls for each type can be done more than once.Example of StudentCall table:StuID | Category | Notes--------------------------01 | Interview | ...01 | Interview | ...02 | Interview | ...02 | Interview | ...02 | FallApp | ...03 | Interview | ...03 | FallApp | ...04 | FallApp | ...Results:StuID0104I have attempted to generate the query with the following, but I realize this doesn't work because potentially students can have 2 records with the same type of category.SELECT StuIDFROM (SELECT * FROM [StudentCalls] WHERE Category='Interview' OR Category='FallApp')GROUP BY StuIDHAVING Count(StuID) > 1;Any suggestions is appreciated. Thank you! |
|
GilaMonster
Master Smack Fu Yak Hacker
4507 Posts |
Posted - 2010-10-25 : 16:54:38
|
WHERE NOT EXISTS (subquery that checks for an interview) OR NOT EXISTS (subquery that checks for a FallApp)--Gail ShawSQL Server MVP |
 |
|
ahjeck
Starting Member
6 Posts |
Posted - 2010-10-25 : 22:37:22
|
Thanks for the reply GilaMonster. This is exactly what I need. After careful thought, this query makes perfect sense. Thanks again! |
 |
|
|
|
|