SQL reference
Core SQL clauses, patterns, and production-safe query semantics.
SQL reference
This section is the quick-start map for the SQL patterns that most often create bugs during feature work, reporting, and analytics pipelines.
Core areas
Core SQL
NULLs, ordering, grouping, and the semantics that matter in real queries.
Functions
Window functions and scalar functions you use in performance-sensitive queries.
Joins
How table relationships are expressed and where logic goes wrong.
Window functions
ROW_NUMBER, RANK, and cumulative logic for per-row calculations.
The most important rules
NULLis not equal to anything in standard SQLORDER BYwithout a stable tiebreaker is not reproducibleGROUP BYchanges the grain of the result set- window functions do not collapse rows like aggregates do
Example
SELECT
customer_id,
COALESCE(MAX(order_date), 'never') AS last_order_date,
SUM(amount) AS lifetime_value
FROM orders
GROUP BY customer_id
ORDER BY customer_id;Shipping discipline
Before shipping a query, confirm:
- which columns are nullable
- how ties should be ordered
- whether the result must be grouped by user, month, or event
- whether a window function is appropriate instead of a group-by aggregate