I have two tables: 'shift' and 'event'. One shift has many events.
Some sample data:
---- shift ----
id - location
1 - mcdonalds
2 - burger king
3 - subway
--- event ---
id - shift_id - type - note
1 - 1 - 2 - bingo
2 - 1 - 3 - bingo
3 - 2 - 4 - ignore
4 - 2 - 2 - ignore
An event has a type, so for example: type '4' represents an event starting a shift.
I want to build a query that returns all shifts that DO NOT have an event record where type = 4. So in the example above, I would bring back mcdonalds.
I've got as far as:
SELECT
shift.location AS location,
FROM shift
LEFT JOIN event ON event.shift_id=shift.id
and that's where I get stuck. Obviously one can add
WHERE event.type IS NULL
..but how does one only return rows where the null is for type = 4 ?
Thanks....!
on event.shift_id=shift.id and shift.type = 4