Unpaid Bookings
Return booking_id, user_id, listing_id, nights, and booking_date for all bookings with no matching payment, ordered by booking_id.
- Subqueries
- Filtering
- Sorting
Challenge brief
Understand the request
Finance — Collections Finance runs a daily collections sweep to flag bookings that were confirmed but never paid so they can follow up before check-in.
Identify bookings that have no payment record.
Return
- booking_id
- user_id
- listing_id
- nights
- booking_date
Constraints
- Include bookings with no matching payment transaction
- Remain correct when payment booking IDs contain NULL
- Order by booking ID
Data you will use
Review the relevant tables before deciding how to join, filter, or aggregate them.
bookings
booking_idINTEGERuser_idINTEGERlisting_idINTEGERnightsINTEGERbooking_dateDATE
payments
booking_idINTEGER
Hints, when you need them
Open one clue at a time so you still do the reasoning.
Hint 1
Evaluate payment absence for each booking.
Hint 2
Use a correlated absence check that is safe when the payment key can be NULL.
Hint 3
Stabilize the result with booking ID.
Verified SQL answer
Attempt the problem first, then compare structure and reasoning—not just syntax.
Reveal solution and explanation
SELECT b.booking_id, b.user_id, b.listing_id, b.nights, b.booking_date FROM bookings b WHERE NOT EXISTS (SELECT 1 FROM payments p WHERE p.booking_id = b.booking_id) ORDER BY b.booking_idWhy this works
The subquery returns every booking_id that has a payment. NOT IN excludes those, leaving only the three unpaid bookings (9, 10, 11).
Success check
Returns every unpaid booking without NULL-sensitive exclusions
Expected result
Use this output to verify values, aliases, ordering, and row count.
| booking_id | user_id | listing_id | nights | booking_date |
|---|---|---|---|---|
| 9 | 2 | 3 | 2 | 2023-08-15 |
| 10 | 3 | 1 | 3 | 2023-08-20 |
| 11 | 2 | 1 | 4 | 2023-09-01 |
Learn the concepts behind this answer
Strengthen your understanding with these targeted learning topics:
Continue practicing
Explore related company challenges
Uber
Independent Uber-style mobility marketplace SQL practice covering trips, drivers, riders, pricing, payments, and promotions.
Amazon
Independent Amazon-style e-commerce, warehouse, inventory, and customer analytics SQL practice.
Meta
Independent Meta-style social-product, engagement, content, community, messaging, and advertising SQL practice.
Return to the complete interview preparation experience.