Latest Booking per Room
Problem
A hotel records every room booking. For each room, find its **most recent booking(s)** by booking date. If two or more bookings for the same room share the latest date, return all of them.
Return `room_name`, `room_id`, `booking_id`, and `booked_on`. Order by `room_name`, then `room_id`, then `booking_id`.
Tables
Example rows — the live problem includes the full dataset.
guests
| guest_id | guest_name |
|---|---|
| 1 | Wendell |
| 2 | Bianca |
| 3 | Soraya |
bookings
| booking_id | booked_on | guest_id | room_id |
|---|---|---|---|
| 1 | 2021-07-31 | 1 | 1 |
| 2 | 2021-07-30 | 2 | 2 |
| 3 | 2021-08-29 | 3 | 3 |
rooms
| room_id | room_name | nightly_rate |
|---|---|---|
| 1 | Garden Suite | 120 |
| 2 | Loft | 80 |
| 3 | Penthouse | 600 |
Expected output
Your answer should return 4 rows with the columns room_name, room_id, booking_id, booked_on.
Starter code (SQL)
SELECT *
FROM guests;Solve this SQL question free
Write SQL and run it instantly in your browser — even on your phone. No signup needed to try.
Solution & explanation
Create a free account to unlock the optimal solution, a step-by-step explanation, and the hidden test cases that grade your answer.
Sign up free to unlock