Compact recall reference — full reasoning lives in the linked modules and questions.
FROM → JOIN → WHERE → GROUP BY → HAVING → SELECT → DISTINCT → ORDER BY → LIMIT
Window functions evaluate around SELECT — after WHERE/GROUP BY/HAVING.
| Trap | The bug |
|—|—|
| NOT IN with nullable subquery | Silently returns zero rows if any NULL present (Q007) |
| LEFT JOIN + COUNT(*) | Reports 1, not 0, for unmatched rows — use COUNT(joined_col) (Q006) |
| Duplicate rows after JOIN | One-to-many fan-out — check cardinality before aggregating |
| Window ORDER BY misunderstood | Determines ranking AND the default frame for aggregate window functions |
| Integer division | 5/2 = 2 — cast explicitly |
| Timezone/date boundary | Filter shifts which “day” a row falls in without explicit handling |
| COUNT(*) vs COUNT(col) | Latter excludes NULLs (Q003) |
| DISTINCT hiding duplication | Masks a join fan-out instead of fixing it |
| Non-SARGable predicate | Function wrapping an indexed column defeats the index (Q017) |
| Implicit conversion | Mismatched types can defeat an index or produce wrong matches |
| Function | Ties |
|—|—|
| ROW_NUMBER() | Never ties — arbitrary tiebreaker order |
| RANK() | Ties share rank; next rank skips ahead |
| DENSE_RANK() | Ties share rank; no skip |
| LAG/LEAD | Look back/forward n rows in partition order; NULL at edges |
| Join | Behavior | |—|—| | INNER | Only matching rows both sides | | LEFT | All left rows; unmatched right = NULL | | FULL OUTER | All rows both sides; unmatched = NULL on missing side | | CROSS | Every combination — deliberate cartesian product |
NULL = NULL → UNKNOWN, not TRUENULL != X → UNKNOWN — why !=/NOT IN silently break on NULLsIS NULL/IS NOT NULL, never = NULL