If starttime
and endtime
columns are in TIME
format then this queries should solve your problem:
Because as mysql documentation say "If the NO_ZERO_DATE or NO_ZERO_IN_DATE SQL mode is enabled, zero dates or part of dates are disallowed." you may need to execute this query first:
SET sql_mode = '';
then the second one (if starttime and endtime columns are in TIME format):
SELECT *
FROM `tables`
INNER JOIN reservation_table
ON `tables`.`id` = reservation_table.table_id
INNER JOIN reservations
ON reservations.id = reservation_table.reservation_id
INNER JOIN customers
ON customers.id = reservations.customer_id
WHERE `date` = '2016-11-02'
AND ( starttime <= str_to_date('19:42', '%H:%i')
AND starttime >= str_to_date('16:42' , '%H:%i'))
but if these columns are not in that format do:
SELECT *
FROM `tables`
INNER JOIN reservation_table
ON `tables`.`id` = reservation_table.table_id
INNER JOIN reservations
ON reservations.id = reservation_table.reservation_id
INNER JOIN customers
ON customers.id = reservations.customer_id
WHERE `date` = '2016-11-02'
AND ( str_to_date(starttime, '%H:%i') <= str_to_date('19:42', '%H:%i')
AND str_to_date(starttime, '%H:%i') >= str_to_date('16:42' , '%H:%i'))