List Items from One Table Who's ID doesn't appear in another

G’day Everyone,

Just wondering if there is an SQl Guru out there that can help with this query.

I have 2 tables:

TIMES: id, time
BOOKINGS: id, timesid, teacherid, studentid

I want to get all the times out of the TIMES table who’s id (timesid) does not appear in the BOOKINGS table

I have tried this but to no avail


SELECT times.ID FROM times
INNER JOIN bookings ON times.id = bookings.timesid
WHERE times.id != bookings.id

I wait in hope!

r937

That is Brilliant!!! exactly what I needed

Cheers

you were close, but you need a LEFT OUTER JOIN instead

SELECT times.ID 
  FROM times
LEFT OUTER 
  JOIN bookings 
    ON bookings.timesid = times.id
 WHERE bookings.timesid IS NULL

:cool: