Subquery Basics: Scalar and Single Row Subqueries
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...
Notes related to SQL.
131 notes tagged
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...
Why a join multiplies rows, how to detect it, and the anti join patterns that answer "which rows have no match at all".
Building queries across four or more tables: reading a join chain, non equality conditions, join order, and keeping a long query readable.
The three joins people meet last: keeping unmatched rows from both sides, deliberate Cartesian products, and joining a table to itself.
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...
INNER JOIN keeps only rows that match on both sides. Learn the syntax, how the join condition works, and why unmatched rows silently disappear.
Grouping by several columns, grouping by expressions, and the totals features - ROLLUP, CUBE and GROUPING SETS - that add subtotal rows.
HAVING filters groups after aggregation, WHERE filters rows before it. Learn when each applies, why using both is usually correct, and which is faster...
GROUP BY collapses rows into one row per distinct key. Learn the single rule that governs the select list and how NULLs are grouped.
Aggregating an expression rather than a column: weighted totals, conditional counts and the difference between counting rows and counting facts.
The five aggregate functions that collapse many rows into one value, the three forms of COUNT, and what each one does with NULL.
SQL conditions return three results, not two. Learn the AND, OR and NOT truth tables, why NOT IN breaks on NULL, and the NULL safe comparison operator...