Medium
SQL-O05sqlSpotting & Fixing N+1 Queries
Problem
An ORM is issuing 1 query for the orders list and then 1 query *per order* to fetch the customer name (1+N). Identify the anti-pattern and rewrite it as a single SQL.
Input
Conceptual + SQL.
Output
Single JOIN query
Constraints
—
Sample input
—
Sample output
N+1 is fixed by JOINing once.
Explanation
The ORM is lazy-loading customer per row. A single JOIN replaces N+1 round-trips.
optimisationanti-patternjoins@Shopify
Visible test cases
in: explain
out: ok
Your solution — run it, use AI if stuck
sql
