Where to go next with SQL
A concrete path from fundamentals to job-ready
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.
Constraints deep-dive
FOREIGN KEY relationships, CHECK rules, UNIQUE — schemas where data cannot lie.
Subqueries & CTEs
WITH top_earners AS (SELECT …) — build complex logic in named, readable layers instead of one monster query.
Window functions
ROW_NUMBER(), RANK(), SUM() OVER (PARTITION BY …) — analytics that keep every row instead of collapsing them.
Indexes & EXPLAIN
Learn why a query is slow and prove the fix: read the query plan, add the index, re-measure.
Deliberate practice
Two or three real problems daily on real-style datasets until the syntax is muscle memory.
1SELECT department, name, salary,2 RANK() OVER (PARTITION BY department ORDER BY salary DESC) AS rank_in_dept3FROM employees;
| department | name | salary | rank_in_dept |
|---|---|---|---|
| Engineering | Cynthia | 91000 | 1 |
| Engineering | Alice | 85000 | 2 |
| Engineering | Farid | 73000 | 3 |
| Sales | Elena | 58000 | 1 |
| Sales | Bob | 52000 | 2 |
| Marketing | David | 47000 | 1 |
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.
CTE — layered logic
WITH names an intermediate result you can query.
1WITH eng AS (2 SELECT * FROM employees WHERE department = 'Engineering'3)4SELECT name, salary FROM eng WHERE salary > 80000;
| name | salary |
|---|---|
| Alice | 85000 |
| Cynthia | 91000 |
Window function — rank in group
Rank rows without collapsing them.
1SELECT department, name, salary,2 RANK() OVER (PARTITION BY department ORDER BY salary DESC) AS rank_in_dept3FROM employees;
| department | name | salary | rank_in_dept |
|---|---|---|---|
| Engineering | Cynthia | 91000 | 1 |
| Engineering | Alice | 85000 | 2 |
| Engineering | Farid | 73000 | 3 |
| Sales | Elena | 58000 | 1 |
| Sales | Bob | 52000 | 2 |
| Marketing | David | 47000 | 1 |
EXISTS — semi-join
Test related rows without joining them.
1SELECT d.dept_id FROM departments d2WHERE EXISTS (3 SELECT 1 FROM employees e WHERE e.department = d.dept_id4);
| dept_id |
|---|
| Engineering |
| Sales |
| Marketing |
EXPLAIN — see the plan
Ask the engine how it will execute.
1EXPLAIN SELECT name FROM employees WHERE salary > 80000;
Recommended resourcesAffiliate links · may earn us a commission
Recommended for learners
Practice what you learned
Take the queries you just visualized and see the data structures that power real databases.