Trips Without Ratings
Which completed trips have no rating record at all?
- Joins
- NULL handling
- Filtering
- Sorting
Challenge brief
Understand the request
Trust & Safety is investigating why some completed trips have no rating submitted — these need follow-up to maintain platform quality.
Find trips with no entry in the ratings table using an anti-join.
Return
- trip_id
- rider_name (full name)
- driver_name (full name)
- fare_amount
Constraints
- Return only trips whose status is 'completed'
- Exclude any trip that has a rating record
- Order by trip ID
Data you will use
Review the relevant tables before deciding how to join, filter, or aggregate them.
trips
trip_idINTEGERrider_idINTEGERdriver_idINTEGERfare_amountREAL
riders
rider_idINTEGERfirst_nameVARCHAR(50)last_nameVARCHAR(50)
drivers
driver_idINTEGERfirst_nameVARCHAR(50)last_nameVARCHAR(50)
ratings
rating_idINTEGERtrip_idINTEGER
Hints, when you need them
Open one clue at a time so you still do the reasoning.
Hint 1
You need trips with NO matching row in ratings. This is an anti-join: LEFT JOIN trips to ratings, then keep only rows where the ratings side is NULL — meaning no rating was submitted.
Hint 2
INNER JOIN trips to riders and drivers for names. LEFT JOIN ratings on trip_id. WHERE rt.rating_id IS NULL keeps only unrated trips.
Hint 3
Preserve completed trips while optionally matching ratings, then keep only rows where the rating-side key is absent.
Verified SQL answer
Attempt the problem first, then compare structure and reasoning—not just syntax.
Reveal solution and explanation
SELECT t.trip_id, r.first_name || ' ' || r.last_name AS rider_name, d.first_name || ' ' || d.last_name AS driver_name, t.fare_amount FROM trips t INNER JOIN riders r ON t.rider_id = r.rider_id INNER JOIN drivers d ON t.driver_id = d.driver_id LEFT JOIN ratings rt ON t.trip_id = rt.trip_id WHERE t.trip_status = 'completed' AND rt.rating_id IS NULL ORDER BY t.trip_idWhy this works
Trips 1001-1004 all have rating rows; 1005 and 1006 do not. LEFT JOIN keeps all trips rows — unmatched ones have NULL in all ratings columns. WHERE rating_id IS NULL isolates those two unrated trips.
Success check
2 trips — trip 1005 (Emma Evans / David Brown, $35) and trip 1006 (Alice Anderson / John Doe, $22)
Expected result
Use this output to verify values, aliases, ordering, and row count.
| trip_id | rider_name | driver_name | fare_amount |
|---|---|---|---|
| 1005 | Emma Evans | David Brown | 35 |
| 1006 | Alice Anderson | John Doe | 22 |
Learn the concepts behind this answer
Strengthen your understanding with these targeted learning topics:
Continue practicing
Explore related company challenges
Airbnb
Independent Airbnb-style marketplace, booking, listing, payment, review, and guest analytics SQL practice.
Amazon
Independent Amazon-style e-commerce, warehouse, inventory, and customer analytics SQL practice.
Google
Independent Google-style search, advertising, user-engagement, and video-product SQL practice.
Return to the complete interview preparation experience.