SELECT / WHERE / JOIN
Filtering rows and combining tables — the majority of queries you will ever write or debug.
Lesson 2 of 2
Debugging a slow query a PM flagged as "the app is broken" is usually a five-minute fix once you know what to look for.
Four concepts cover most of what a working app developer touches day to day.
Filtering rows and combining tables — the majority of queries you will ever write or debug.
Collapsing many rows into a summary — counts, sums, averages per group — the shape behind almost every dashboard number.
A lookup structure that lets the database find matching rows without scanning the whole table — the difference between instant and timed-out.
A group of writes that either all succeed or all roll back together — what keeps a multi-step operation from leaving data half-updated.
A handful of terms let you read an existing schema without a tutorial.
A primary key uniquely identifies a row in its own table; a foreign key is a column referencing a primary key in another table, establishing a relationship between them. Most schemas boil down to one-to-many relationships (one customer, many orders) and occasionally many-to-many ones (many students, many courses) via a join table in between.
Look at the sanitized query and fix below, then work through both exercises.
-- Flagged by a PM as "the app is broken" — actually just slow
select * from orders
where customer_email = 'someone@example.com';
-- 4.2s on a 12M-row table, no index on customer_email
-- After adding an index:
create index idx_orders_customer_email on orders (customer_email);
-- same query: 8msAnswer in your head first, then click a question to reveal the answer.
Work through the sample slow query and check each item off. Progress is saved in your browser.
These primers are a starting point. Read the primary sources to build real fluency.
What building this project taught me.
SQL fluency wasn't a named gap in the job-hunting scan, but it was one of the most frequently required skills across all 30+ job descriptions reviewed — hence its place here rather than a dedicated module of its own.
Enough SQL and data modeling to read an unfamiliar schema is the shared prerequisite between this app-dev-facing lesson and the Data Engineering Trail's Modern Data Stack Foundations lesson.