Basic SQL for Marketers
Part of the Digital Marketing Roadmap
In short
When the dashboard doesn't have your answer, SQL lets you ask the data directly. A few clauses will cover most marketing questions you'll ever have.
Enough SQL to pull your own campaign or customer data without waiting on an analyst — SELECT, WHERE, GROUP BY and basic JOINs cover most of a marketer's real needs.

Think of it like this
Asking the college office clerk
You ask the clerk: 'From the admissions register, only this year's students, count them by city, biggest first.' He flips through, groups and counts. A SQL query is that request, written so the database understands it.
Watch it happen
The order a database runs your query
1/5Start with the orders table: every order, every column.
The big ideas
What you need to know
Tables and rows
Data lives in tables like orders or users. Each row is one record, each column one detail.
WHERE filters rows
Keep only the rows you care about, like one month, one city or one campaign.
GROUP BY summarises
Combine rows by a column, then use COUNT, SUM or AVG on each group.
JOIN combines tables
Connect orders to users by user_id to answer questions like 'revenue by sign-up channel'.
See it in code
Walk through the code
1SELECT2 channel,3 COUNT(*) AS orders,4 SUM(amount) AS revenue,5 ROUND(AVG(amount), 0) AS avg_order6FROM orders7WHERE order_date >= '2026-10-01'8 AND order_date < '2026-11-01'9GROUP BY channel10ORDER BY revenue DESC;1/3Pick the channel and three summaries: order count, total and average.
Revenue by channel for October. This one pattern answers a huge number of marketing questions.
Save yourself the pain
Common mistakes
Oops
Using WHERE to filter on a COUNT or SUM.
Do this instead
WHERE runs before grouping. Use HAVING to filter groups, like HAVING COUNT(*) > 10.
Oops
Writing dates as order_date <= '2026-10-31' for timestamps.
Do this instead
Use < '2026-11-01' so orders later on the 31st aren't missed.
Your mission
Run your first queries
Quick check
You want only channels with more than 50 orders. Which clause do you add?
Go deeper
- 1Complete a beginner SQL course or interactive tutorial (many are free).
- 2Practice writing a query to count conversions by campaign from a sample dataset.
- 3Learn enough JOIN logic to combine a campaigns table with a conversions table.
More topics at this stop
Stuck on this topic? Ask an Insider
Get 1:1 guidance from people who've walked this exact path — on the InsideEdge app.