Joining Marketing Tables
Sessions, users, orders.
Why Join?
Real questions span tables. Spend lives in campaigns, revenue in orders, traits in users. To compute ROAS or LTV by segment, you must combine them.
JOINs match rows from two tables on a shared key, like user_id or campaign_id.
SELECT o.order_id, u.country
FROM orders o
JOIN users u ON o.user_id = u.user_id;INNER JOIN
An INNER JOIN returns only rows that match in both tables. Orders without a matching user, or users without orders, are dropped.
Use it when you only care about records that exist on both sides, such as purchasers.
SELECT u.user_id, u.country, SUM(o.revenue) AS revenue
FROM users u
JOIN orders o ON o.user_id = u.user_id
GROUP BY u.user_id, u.country;All lessons in this course
- Why Marketers Learn SQL
- SELECT, WHERE, GROUP BY
- Joining Marketing Tables
- Cohort and Funnel Queries