0
← Exercises/
Joins•7 of 12
JoinsIntermediatePRO

Fleet Vehicle Compliance Audit with Multi-Table JOIN

Scenario

Municipal transport authorities require rideshare networks to audit trips where the vehicle used was overdue for mandatory safety inspection.

Task
Join `rides` with `drivers` and `vehicles` across three tables: - `rides.driver_id = drivers.driver_id` - `rides.vehicle_id = vehicles.vehicle_id` Return: 1. `r.ride_id` 2. `d.driver_name` 3. `v.license_plate` 4. `v.model` 5. `r.fare_amount` Filter to only include trips where `v.inspection_passed = false`. Order results by `r.fare_amount` descending, then by `r.ride_id` ascending.
Expected Output Format

Trips performed with uninspected vehicles sorted by fare amount.

Input Tables & Sample Data0 tables
Loading database schema...
Need a hint?
query.sql|Local Sandbox
Loading SQL editor...
Click "Run" or press ⌘ + Enter to execute your query

About the “Fleet Vehicle Compliance Audit with Multi-Table JOIN” SQL Problem

Business Scenario

Municipal transport authorities require rideshare networks to audit trips where the vehicle used was overdue for mandatory safety inspection.

Expected Output & Criteria

Trips performed with uninspected vehicles sorted by fare amount.

Database Table Schema (PostgreSQL DDL)

PostgreSQL 16 WASM

This challenge executes directly against the following relational schema in your browser:

CREATE TABLE drivers (
        driver_id INT PRIMARY KEY,
        driver_name VARCHAR(80) NOT NULL
      );

      CREATE TABLE vehicles (
        vehicle_id INT PRIMARY KEY,
        license_plate VARCHAR(20) NOT NULL,
        model VARCHAR(50) NOT NULL,
        inspection_passed BOOLEAN NOT NULL
      );

      CREATE TABLE rides (
        ride_id INT PRIMARY KEY,
        driver_id INT REFERENCES drivers(driver_id),
        vehicle_id INT REFERENCES vehicles(vehicle_id),
        fare_amount NUMERIC(8, 2) NOT NULL
      );

Target SQL Clauses & Operators

JOINWHEREORDER BY

Want more Joins practice?

Explore the full syllabus of 12 exercises, syntax guides, and interview pitfalls.

View Joins Track→