Learn SQL
-- nextsteps.next_steps

Where to go next with SQL

A concrete path from fundamentals to job-ready

--concept

You now command the core 20% of SQL that answers 95% of questions. The next tier adds precision and power: constraints that protect data, subqueries and CTEs that compose complex logic, window functions that rank and compare without collapsing rows, and indexes that make it all fast. After that it is deliberate practice on real datasets.

--how it works
1

Constraints deep-dive

FOREIGN KEY relationships, CHECK rules, UNIQUE — schemas where data cannot lie.

2

Subqueries & CTEs

WITH top_earners AS (SELECT …) — build complex logic in named, readable layers instead of one monster query.

3

Window functions

ROW_NUMBER(), RANK(), SUM() OVER (PARTITION BY …) — analytics that keep every row instead of collapsing them.

4

Indexes & EXPLAIN

Learn why a query is slow and prove the fix: read the query plan, add the index, re-measure.

5

Deliberate practice

Two or three real problems daily on real-style datasets until the syntax is muscle memory.

--visualization
🔒Constraints🧩Subqueries & CTEs🪟Window Functions🚀Indexes & EXPLAIN🏋️Deliberate practiceYOU ARE HERE
completed milestone ahead
Stage 1 / 7
You own the core 20% that answers 95% of questions. Here is the road ahead.
--example
query.sql
1SELECT department, name, salary,
2 RANK() OVER (PARTITION BY department ORDER BY salary DESC) AS rank_in_dept
3FROM employees;
Result
departmentnamesalaryrank_in_dept
EngineeringCynthia910001
EngineeringAlice850002
EngineeringFarid730003
SalesElena580001
SalesBob520002
MarketingDavid470001

A taste of window functions: ranking inside each department while keeping every row — impossible with plain GROUP BY. Follow the roadmap visualization for the full journey.

--variants

CTE — layered logic

WITH names an intermediate result you can query.

query.sql
1WITH eng AS (
2 SELECT * FROM employees WHERE department = 'Engineering'
3)
4SELECT name, salary FROM eng WHERE salary > 80000;
Result
namesalary
Alice85000
Cynthia91000
1The CTE builds the Engineering slice first, with a name.
2The outer query filters that slice further.
3Same result as one fused query — but readable and reusable.

Window function — rank in group

Rank rows without collapsing them.

query.sql
1SELECT department, name, salary,
2 RANK() OVER (PARTITION BY department ORDER BY salary DESC) AS rank_in_dept
3FROM employees;
Result
departmentnamesalaryrank_in_dept
EngineeringCynthia910001
EngineeringAlice850002
EngineeringFarid730003
SalesElena580001
SalesBob520002
MarketingDavid470001
1PARTITION BY department slices rows per team — like GROUP BY, but rows survive.
2ORDER BY salary DESC ranks within each slice.
3Six rows in, six rows out — each with its rank attached.

EXISTS — semi-join

Test related rows without joining them.

query.sql
1SELECT d.dept_id FROM departments d
2WHERE EXISTS (
3 SELECT 1 FROM employees e WHERE e.department = d.dept_id
4);
Result
dept_id
Engineering
Sales
Marketing
1For each department, the subquery asks "anyone here?".
2Departments with staff survive; empty ones (imagine Research) drop.
3EXISTS avoids the NOT IN + NULL trap entirely.

EXPLAIN — see the plan

Ask the engine how it will execute.

query.sql
1EXPLAIN SELECT name FROM employees WHERE salary > 80000;
1EXPLAIN prints the plan: scan type, indexes used, estimated rows.
2Look for "Seq Scan" on big tables where an index should serve.
3The habit: measure, explain, index, re-measure.
--key facts
Practice platformsSQLZoo, pgexercises, StrataScratch
Local sandboxSQLite + DB Browser — zero-config playground on any laptop
Portfolio signalan analysed public dataset on GitHub speaks louder than certificates
--use cases
From fundamentals to job-ready: subqueries, windows and indexes are the working tier
Interview prep: window functions and CTEs dominate modern SQL interviews
Real analytics: rankings, running totals, cohort retention
Performance work: EXPLAIN + indexes as a daily habit
--under the hood
Window functions compute per row over a partition — visually, GROUP BY and SELECT at once; engines implement them with sort-based windows.
EXPLAIN (ANALYZE) in PostgreSQL actually runs the query and reports real timings — the single most useful performance tool you will learn.

Recommended resourcesAffiliate links · may earn us a commission

Recommended for learners

Structured coding coursesVideo courses that pair well with visual practice — pick one language and go deep.Browse courses Pro code editor & AI assistantWrite, debug and explain code faster while you practice the patterns here.Try it free Classic DSA interview booksThe reference books interviewers themselves learned from — great next to the visualizers.See the books

Practice what you learned

Take the queries you just visualized and see the data structures that power real databases.