-1

I am trying to get a list of all available timeslots for a specific date by left joining my timeslot table with me schedule table.

SELECT * 
FROM `timeslots` 
LEFT JOIN schedule ON timeslots.timeslot_id = schedule.schedule_timeslot 
LIMIT 0, 30

This returns:

enter image description here

What I want returned are all the rows that are null for the last 3 fields. So given the date 2011-08-01 I want all the timeslots returned except for 08:30 - 10:30. I'm assuming some sort of sub-query is needed but I don't know how to go about it.

Any help would be appreciated.

2 Answers 2

2

Try this one:

SELECT * 
FROM `timeslots` 
LEFT JOIN schedule ON timeslots.timeslot_id = schedule.schedule_timeslot
WHERE  schedule.schedule_id IS NULL or schedule.schedule_date <> '2011-08-01'
LIMIT 0, 30
0
1

Just add a WHERE

SELECT * 
FROM `timeslots` 
LEFT JOIN schedule ON timeslots.timeslot_id = schedule.schedule_timeslot 
WHERE schedule.schedule_timeslot IS NULL
LIMIT 0, 30
2
  • But I believe that removes the timeslot for 2011-08-02 as well and I don't want that. Only the ones for 2011-08-01 or some arbitrary date. - Thanks Aug 28, 2011 at 17:44
  • @PhoenixDown: you said "What I want returned are all the rows that are null for the last 3 fields". I've done that. Fix your question please
    – gbn
    Aug 28, 2011 at 17:46

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.