I'm not quite sure what this is called, but I've spent some time thinking about it and I'm not sure how to approach it. I'm sure it's really simple.
I have two tables, foo and bar. They're related like this:
Foo Table:
| id | name
--------------
| 1 | blah
| 2 | blarg
| 3 | blag
Bar Table (the meaning of baz is irrelevant) :
| fooId | baz |
---------------
| 1 | 100 |
| 1 | 94 |
| 1 | 27 |
| 2 | 94 |
| 3 | 19 |
So, multiple Bars per Foo. I want to select all Foos where they have a baz of 94, unless they also have a baz of 100. So in the above case I only want to select the Foo with an id of 2.
I tried doing something along the lines of:
SELECT id FROM foo
LEFT JOIN bar
ON foo.id = bar.fooId
WHERE bar.baz = 94
AND bar.baz != 100
But obviously that only got me so far. I'm sure there's probably some kind of group by clause in here, but I'm not exactly sure what it should be.
Thanks in advance!
EDIT: In case anyone else has this problem, as @iu mentioned, the term for this is an anti-join.