COUNT, SUM, AVG, MIN and MAX
The five aggregate functions that collapse many rows into one value, the three forms of COUNT, and what each one does with NULL.
A complete SQL path: fundamentals, DDL and DML, querying, joins, subqueries, CTEs, window functions, design, indexing, transactions, performance and security.
91 notes in 31 topics
The five aggregate functions that collapse many rows into one value, the three forms of COUNT, and what each one does with NULL.
Aggregating an expression rather than a column: weighted totals, conditional counts and the difference between counting rows and counting facts.
GROUP BY collapses rows into one row per distinct key. Learn the single rule that governs the select list and how NULLs are grouped.
HAVING filters groups after aggregation, WHERE filters rows before it. Learn when each applies, why using both is usually correct, and which is faster...
Grouping by several columns, grouping by expressions, and the totals features - ROLLUP, CUBE and GROUPING SETS - that add subtotal rows.
INNER JOIN keeps only rows that match on both sides. Learn the syntax, how the join condition works, and why unmatched rows silently disappear.
Outer joins keep unmatched rows and fill the missing side with NULL. Learn LEFT and RIGHT JOIN, and the one mistake that silently turns an outer join...
The three joins people meet last: keeping unmatched rows from both sides, deliberate Cartesian products, and joining a table to itself.
Building queries across four or more tables: reading a join chain, non equality conditions, join order, and keeping a long query readable.
Why a join multiplies rows, how to detect it, and the anti join patterns that answer "which rows have no match at all".
A query inside a query. Learn where a subquery may appear, what each position requires it to return, and the error a scalar subquery raises when it re...
Subqueries that return a list of values, and the three operators that consume them - including the NULL trap that makes NOT IN return nothing.