AnalystPath

Latest Booking per Room

SQLMediumMid level~15 min

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_idguest_name
1Wendell
2Bianca
3Soraya
bookings
booking_idbooked_onguest_idroom_id
12021-07-3111
22021-07-3022
32021-08-2933
rooms
room_idroom_namenightly_rate
1Garden Suite120
2Loft80
3Penthouse600

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

Related SQL questions