Strong SQL analysis comes from understanding data meaning, not from memorising isolated clauses. These 25 concepts form a practical checklist for analysts.
Foundations 1–8
- Table grain: what one row represents.
- Primary keys: row identity.
- Foreign keys: relationships.
- NULL: unknown or absent, not automatically zero.
- WHERE: row filtering before grouping.
- ORDER BY: explicit result ordering.
- DISTINCT: duplicate projection removal, not a join fix.
- Aliases: readable names for tables and expressions.
Analysis 9–16
- INNER JOIN for matched relationships.
- LEFT JOIN for preserving the left population.
- Join cardinality and row multiplication.
- GROUP BY and aggregate grain.
- HAVING for aggregate filters.
- CASE for conditional logic.
- COALESCE for explicit missing-value fallback.
- Subqueries and EXISTS for relationship tests.
Advanced 17–25
- CTEs for readable stages.
- Recursive CTEs for hierarchies.
- Window functions without collapsing rows.
- ROW_NUMBER, RANK and DENSE_RANK.
- LAG/LEAD for neighbouring rows.
- Running totals and frames.
- Dates and time zones.
- Indexes and EXPLAIN plans.
- Transactions and isolation.
WITH ranked AS (
SELECT department_id, employee_id, salary,
DENSE_RANK() OVER (
PARTITION BY department_id ORDER BY salary DESC
) AS salary_rank
FROM employees
)
SELECT *
FROM ranked
WHERE salary_rank <= 2;
This returns the top two salary levels per department and preserves ties. The CTE creates a named stage; the window function ranks without collapsing employee rows.
Common mistakes and next step
Check null semantics, duplicate keys, date boundaries and the output grain. Never use DISTINCT to conceal an unexplained multiplication. Practise in the SQL Interview Guide. Further reading: MySQL 8 documentation.