SQL guides
Every published SQL guide, newest first, with practical examples you can copy into your own project.
3,815 guides across 14 topics
Topics
Popular SQL guides
Most readLatest SQL guides
Page 2 of 2SQL NULL Handling: COALESCE, NULLIF, IS NULL, and Three-Valued Logic
Why every comparison with NULL is UNKNOWN, why NOT IN can return nothing, and how unique indexes, sorting and NOT NULL migrations behave with NULL.
SQL UPSERT: INSERT ON CONFLICT, MERGE Statements, and Duplication Handling
The dialect split between ON CONFLICT, ON DUPLICATE KEY UPDATE and MERGE, why DO NOTHING breaks RETURNING, and the deadlocks bulk upserts cause.
SQL CASE WHEN: Conditional Logic in SELECT, WHERE, and UPDATE Statements
Searched versus simple CASE, the omitted ELSE that writes NULL in an UPDATE, branch type unification, and pivoting rows into columns.
SQL Transactions: ACID Properties, Isolation Levels, and Deadlock Prevention
Which anomaly each isolation level still allows, why READ COMMITTED permits lost updates, and the lock ordering plus retry loop every deadlock needs.
SQL Subqueries: Correlated vs Uncorrelated, EXISTS, IN, and Performance
What makes a subquery run once versus once per row, why NOT IN returns nothing when the inner column has a NULL, and when IN beats a join.
SQL GROUP BY and HAVING: Aggregation Functions, Filters, and Common Pitfalls
The evaluation order that decides WHERE versus HAVING, why COUNT(*) and COUNT(col) disagree on left joins, and how ROLLUP subtotals hide in NULL.
SQL CTEs: Common Table Expressions and Recursive WITH Queries Explained
When a CTE is inlined and when it becomes an optimisation fence, plus recursive hierarchies with depth and cycle guards and data-modifying CTEs.
SQL Indexes: B-Tree, Composite Indexes, and Covering Indexes for Query Performance
Why composite column order decides whether an index is used, how a covering index removes the heap fetch, and which indexes to drop because nothing reads them.
SQL Joins: INNER, LEFT, RIGHT, FULL OUTER, and CROSS JOIN with Visual Diagrams
Every join type as a match policy, why a WHERE clause on the right table turns LEFT into INNER, and how row multiplication inflates every aggregate.
SQL Window Functions: ROW_NUMBER, RANK, DENSE_RANK, and LEAD/LAG Explained
How the four ranking and offset functions differ on ties, why the default RANGE frame makes running totals repeat, and how LAG builds gap-and-island detection.