SQL
SQL fundamentals, patterns, and best practices
SQL
SQL is the backbone of data work. This section covers patterns and practices that come up often.
Core concepts
- SELECT — Filtering, aggregating, and shaping data
- JOINs — Combining tables (INNER, LEFT, and when to use each)
- Window functions — ROW_NUMBER, RANK, running totals, and partitions
- CTEs — Breaking complex queries into readable steps
Common patterns
Deduplication
Running totals
Date bucketing
Best practices
- Use CTEs instead of nested subqueries when logic gets complex
- Prefer
WHEREoverHAVINGfor row-level filters - Use
COALESCEorNULLIFto handle nulls explicitly - Avoid
SELECT *in production; list columns you need