Core SQL
Build your SQL foundation with logic, ordering, and null semantics that matter in production.
Foundations that trip people up
These pages cover the semantics most likely to cause bad production queries:
NULL handling
What NULL means, how comparisons behave, and how COALESCE helps.
WHERE
Filter rows before grouping, and see how NULL and join filters change the result.
ORDER BY
How ordering works, why ties matter, and how to make output deterministic.
GROUP BY
When aggregates change the shape of your result set.
CASE
Branch on conditions to reshape values for filtering, grouping, and display.
Keep this checklist close
NULLis not equal to anythingORDER BYwithout a tiebreaker is not stableGROUP BYchanges the grain of the result- a query is only safe when the business rule is explicit
Example
SELECT
customer_id,
COALESCE(MAX(order_date), 'never') AS last_order_date,
COUNT(*) AS orders
FROM orders
GROUP BY customer_id
ORDER BY customer_id;