Mysql Help to Return Unavailable Days for Scheduling

Asked

Viewed 30 times

0

I have 2 mysql tables that represent days unavailable for scheduling:

Table Holidays: id, day (date), name

Table special_days: id, day (date), will_work(Boolean)

In the querie I need to select the unavailable days that are the Holidays, the special_days in which will_work. So far so good, but if there is a special_day where the date is equal to some Holiday and will_work is true I need to remove this date from the list.

So far I’ve only managed:

    SELECT day FROM holidays
    UNION SELECT day FROM special_days WHERE will_work = FALSE;

But I could not remove the Holidays where there is some special_day with will_work is true and day equal;

  • Post your code where you are struggling, so it is difficult to help you

2 answers

2


SELECT day
FROM holidays
where day not in (SELECT day FROM special_days WHERE will_work = TRUE)
UNION
SELECT day
FROM special_days
WHERE will_work = FALSE;
  • Thank you very much, it’s all right now !

0

And if you restrict the query by making a subselect to filter only the days:

 SELECT day 
   FROM holidays h 
  WHERE h,day in (SELECT day FROM special_days WHERE will_work = FALSE);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.