I have the following 3 MySQL tables.
I am storing bookings in the bookings
table & the event dates and times in separate MySQL tables.
I want to have a MySQL query to list available times for a specific date.
So if I enter date of value 1
it’ll show no times available but if I enter 2
it’ll output 1 | 9:00
.
INSERT INTO `bookings` (`id`, `email`, `date_requested`, `time_requested`) VALUES
(1, '[email protected]', '1', '1'),
(2, '[email protected]', '1', '2'),
(3, '[email protected]', '2', '2');
INSERT INTO `bookings_dates` (`id`, `date`) VALUES
(1, '2022-11-05'),
(2, '2022-11-06'),
(3, '2022-11-07');
INSERT INTO `bookings_times` (`id`, `time`) VALUES
(1, '9:00'),
(2, '9:15');
2
Answers
You can use a
NOT IN
condition.DEMO
In order to get times for a given day (1) you can use the following query :
Edit1:
In order to get times not in use for a given day (1) you can use the following query :