Active Drivers by City
Which drivers are currently active, which city are they in, and what vehicle type do they drive?
- Joins
- Filtering
- Sorting
Challenge brief
Understand the request
Driver Operations needs a current roster of all active drivers showing their city assignment and vehicle category.
List all active drivers with name, email, city, and vehicle type.
Return
- first_name
- last_name
- city_name
- vehicle_type
Constraints
- Return only drivers whose status is 'active'
- Order by city name, then driver ID so ties are stable
Data you will use
Review the relevant tables before deciding how to join, filter, or aggregate them.
drivers
driver_idINTEGERfirst_nameVARCHAR(50)last_nameVARCHAR(50)emailVARCHAR(100)statusVARCHAR(20)city_idINTEGERvehicle_idINTEGER
cities
city_idINTEGERcity_nameVARCHAR(100)
vehicles
vehicle_idINTEGERvehicle_typeVARCHAR(30)
Hints, when you need them
Open one clue at a time so you still do the reasoning.
Hint 1
Driver names and status are in drivers. City names are in cities. Vehicle types are in vehicles. Two JOINs required: drivers to cities on city_id, and drivers to vehicles on vehicle_id.
Hint 2
INNER JOIN drivers to cities ON d.city_id = c.city_id. INNER JOIN vehicles ON d.vehicle_id = v.vehicle_id. WHERE d.status = 'active'. ORDER BY c.city_name.
Hint 3
Start from drivers, connect the city and vehicle dimensions by their IDs, then apply the active-status filter and stable sort.
Verified SQL answer
Attempt the problem first, then compare structure and reasoning—not just syntax.
Reveal solution and explanation
SELECT d.first_name, d.last_name, d.email, c.city_name, v.vehicle_type FROM drivers d INNER JOIN cities c ON d.city_id = c.city_id INNER JOIN vehicles v ON d.vehicle_id = v.vehicle_id WHERE d.status = 'active' ORDER BY c.city_name, d.driver_idWhy this works
Two INNER JOINs chain from the drivers fact table to two dimension tables. status = 'active' filters only working drivers. All 5 drivers are active so all appear.
Success check
5 active drivers across San Francisco, New York, and Los Angeles
Expected result
Use this output to verify values, aliases, ordering, and row count.
| first_name | last_name | city_name | vehicle_type | |
|---|---|---|---|---|
| David | Brown | david.b@uber.com | Los Angeles | UberX |
| Mike | Johnson | mike.j@uber.com | New York | UberBlack |
| Sarah | Williams | sarah.w@uber.com | New York | UberXL |
| John | Doe | john.doe@uber.com | San Francisco | UberX |
| Jane | Smith | jane.smith@uber.com | San Francisco | UberX |
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.