← Executing queries using Databricks SQL and SQL Warehouses
20% domain · module 2
Joins, set ops, aggregations, and grain
Starts at 37:22 in this video — SQL Warehouse full course — SQL editor patterns (37:22)
Grain first
Most wrong numeric answers are grain mistakes: joining a fact to a duplicated dimension, then SUM. Before aggregating, write “one row per ___”.
Joins (must know differences)
INNER JOIN— matching keys onlyLEFT JOIN— keep all left rows; unmatched right columns NULLRIGHT JOIN— keep all right rowsFULL OUTER JOIN— keep both sides- Filtering
WHERE right.id IS NOT NULLafter a left join turns it into an inner join
Multi-key joins: ON a.k1 = b.k1 AND a.k2 = b.k2.
Set operations
UNION— distinct rowsUNION ALL— keep duplicates (usually faster when you know there are none)
Aggregations the outline names
COUNT(*), COUNT(col) (ignores NULL), approx_count_distinct, AVG / mean, and summary stats (MIN, MAX, STDDEV). COUNT(col) vs COUNT(*) is a real exam distinction.
GROUP BY trap
SELECT region, COUNT(*) FROM customers ORDER BY region fails the requirement “customers per region” because it is missing GROUP BY region.
sqlSELECT region, COUNT(*) AS number_of_customers
FROM catalog.gold.customers
GROUP BY region
ORDER BY region;