Airbnb-style Company ChallengeEasyVerified answerSQLite live

Guest Booking History

Return user_id, country, booking_id, listing_id, and nights for all guests who have bookings, ordered by user_id then booking_id.

  • Joins
  • Sorting

Challenge brief

Understand the request

Customer Experience Customer Experience needs a unified view of each guest's country and booking details to prepare personalised support responses.

Show each guest's bookings with their country, listing, and nights.

Return

  • user_id
  • country
  • booking_id
  • listing_id
  • nights

Constraints

  • Include bookings with a matching registered guest
  • Return one row per booking
  • Order by user ID, then booking ID

Data you will use

Review the relevant tables before deciding how to join, filter, or aggregate them.

users

  • user_idINTEGER
  • countryVARCHAR(50)

bookings

  • user_idINTEGER
  • booking_idINTEGER
  • listing_idINTEGER
  • nightsINTEGER

Hints, when you need them

Open one clue at a time so you still do the reasoning.

Hint 1

Guest country and booking details live in related tables.

Hint 2

Connect each booking to its user key.

Hint 3

Order first by guest and then by booking.

Verified SQL answer

Attempt the problem first, then compare structure and reasoning—not just syntax.

Reveal solution and explanation
SELECT u.user_id, u.country, b.booking_id, b.listing_id, b.nights
FROM users u
JOIN bookings b ON u.user_id = b.user_id
ORDER BY u.user_id, b.booking_id

Why this works

country lives in users; booking details live in bookings. INNER JOIN on user_id combines them. All 8 users have at least one booking so no rows are lost.

Success check

Returns each booking at booking grain with its guest country

Expected result

Use this output to verify values, aliases, ordering, and row count.

user_idcountrybooking_idlisting_idnights
1US851
2IN113
2IN932
2IN1114
3UK225
3UK1013
4CA332
5US444
6FR553
7US612

Previewing 10 of 11 expected rows. Run the query in the editor to inspect the full result.

Learn the concepts behind this answer

Strengthen your understanding with these targeted learning topics:

Continue practicing

SQL Interview Practice

Return to the complete interview preparation experience.