← All SQL interview questions

Double-booked meeting rooms

HardJoins — Self JoinOracleOla

A facilities team needs to find meeting rooms that were booked by two people at the same time. Two bookings overlap only when they are in the same room and each starts before the other ends. A booking that starts exactly when another ends is back-to-back, not a clash.

From room_bookings, return one row per clashing pair: booking_a, booking_b (with booking_a < booking_b), room_id, overlap_minutes and overlap_type, where overlap_type is CONTAINED if one booking fits entirely inside the other and PARTIAL otherwise. Order by room_id, booking_a, booking_b.

Sample data

Table: room_bookings

12 row(s) · showing first 8

booking_idINTroom_idTEXTbooked_byTEXTstart_timeTIMESTAMPend_timeTIMESTAMP
1R1Asha2026-11-022026-11-02
2R1Bharat2026-11-022026-11-02
3R1Chitra2026-11-022026-11-02
4R1Dev2026-11-022026-11-02
5R2Esha2026-11-022026-11-02
6R2Farid2026-11-022026-11-02
7R2Gita2026-11-022026-11-02
8R3Hari2026-11-022026-11-02