Checking for date range conflicts in MySQL

前端 未结 4 1568
不思量自难忘°
不思量自难忘° 2021-02-02 03:25

I am writing a hotel booking system. after lots of studying (including stack overflow) i wrote this sql to find out free rooms:

SELECT
*
FROM room
WHERE
    room         


        
4条回答
  •  情书的邮戳
    2021-02-02 03:31

    I think this might get you started in the right direction...

    SELECT R.*
    FROM room AS R
         LEFT OUTER JOIN bookings AS B USING (room_id)
    WHERE B.room_id IS NULL
          OR (B.checkout < '$check_in'
              AND B.checkin > '$check_out')
    

提交回复
热议问题