Critical Spec
JOIN Types
Real data is split across related tables to avoid duplication. JOIN combines rows from two tables based on a matching key. INNER JOIN returns only matching rows; LEFT JOIN keeps every row from the left table even without a match.
SELECT orders.id, users.name, orders.total
FROM orders
INNER JOIN users ON orders.user_id = users.id;
Critical Spec
GROUP BY & Aggregate Functions
Aggregate functions like COUNT(), SUM(), and AVG() compute a single value across a group of rows, defined by GROUP BY. HAVING filters groups after aggregation, while WHERE filters rows before it.
SELECT user_id, COUNT(*) AS order_count, SUM(total) AS revenue
FROM orders
GROUP BY user_id
HAVING SUM(total) > 100;