Find the Double Booked Rooms

A booking covers starts_on up to but not including ends_on. A booking that ends on 8 March and one that begins on 8 March do not conflict.

Find every pair of bookings for the same room whose dates overlap:

  • room_id
  • a_id — the lower booking id of the pair
  • b_id — the higher booking id of the pair

Report each conflicting pair once, not twice, and never pair a booking with itself.

Order by room_id, then a_id, then b_id.

Expected output


room_id | a_id | b_id
--------+------+-----
1       | 1    | 2
3       | 6    | 7
PostgreSQL

Press Run to start the SQL engine.

SensAI
Beta
Tap the mic to stop voice mode