Skip to main content
Practice

Sort and Limit Recent Reservations

Your front desk team needs a quick snapshot of the latest hotel check-ins, so they can prepare for arrivals and manage room readiness.

You've been asked to extract the 5 most recent bookings from the system using the check-in date.

To complete this, you'll use the ORDER BY clause to sort the data by check_in_date, and the LIMIT clause to keep only the most recent rows.

This type of query is common when building dashboards, reports, or quick-reference tools for operations.


Task

From the bookings table in the hotel_booking.sqlite database, display:

  • hotel_name
  • city
  • check_in_date

Only include the 5 most recent bookings, sorted by check_in_date in descending order.


How to solve it

Write a SQL query in the editor that returns the 5 latest bookings.

Use ORDER BY check_in_date DESC to sort from newest to oldest, and add LIMIT 5 to keep only the most recent records.

Want to learn more?

Join CodeFriends Plus membership or enroll in a course to start your journey.