Analytics and Tracking

SQL

Also called Structured Query Language

The language used to ask questions of data in a warehouse or database and shape the answer into a table.

Quick facts: SQL

Category
Analytics and Tracking
Also called
Structured Query Language
Level
Advanced
Affects
Custom reporting, cross-platform analysis, definition consistency
Where to see it
BigQuery, PostgreSQL, MySQL, Looker Studio custom queries
In this article4
  1. How SQL works
  2. Why SQL matters
  3. Where SQL goes wrong
  4. How to act on it

How SQL works

SQL is how you ask a stored table a question. A query names the columns you want, the table they live in, the conditions a row must meet to be included, and how the results should be grouped and ordered. The database works out how to fetch it; you only describe the answer you want. That is why it reads closer to a request than to programming — select these fields, from this table, where the date falls in this range, grouped by campaign.

Two ideas do most of the work in marketing. Aggregation collapses many rows into one summary row: total spend by campaign, leads by city, sessions by landing page. Joining matches rows in one table to rows in another using a shared key, which is how ad spend meets closed revenue from a CRM, or how a lead record meets the campaign that produced it.

Dialects differ slightly between systems — BigQuery, PostgreSQL and others each have their own functions — but the core is common enough that learning one transfers to the rest.

Why SQL matters

Reporting interfaces answer the questions their designers anticipated. SQL answers the ones they did not. Which landing pages produce leads that actually close, how spend in one channel affects enquiries in another, what a customer from a particular city is worth over a year — none of these fit in a platform report, because the data lives in more than one place.

It also makes a definition permanent. A number produced by clicking through an interface is hard to reproduce and easy to argue about. A number produced by a saved query has its rules written down: anyone can read what counted as a lead and what did not.

Where SQL goes wrong

The dangerous fault is a query that runs cleanly and is still wrong. Join two tables on a key that is not unique and rows multiply, inflating every total. Filter dates on the wrong time zone and a day’s data lands in the wrong bucket. Neither produces an error message; both produce a confident number.

The second is the query nobody can read. A long expression written in a hurry, with no comment saying what it defines, becomes untouchable — and when the definition needs to change, it gets rewritten from scratch and the new figures no longer match the old.

The third is cost. On a warehouse that charges by data scanned, a habit of selecting everything over a full history turns curiosity into an invoice.

How to act on it

Learn enough to read a query even if someone else writes it — selecting, filtering by date, grouping and summing covers most marketing questions, and it is a smaller step than it looks. Check any query that joins tables by confirming the row count behaves as you expect before trusting the totals. Write a comment at the top of each saved query saying, in plain words, what it counts. Then point a dashboard at the query’s output rather than making readers run anything, and keep the raw tables in BigQuery or whichever warehouse you use out of client view.

Do and do not

Do

  • Comment each saved query with what it actually counts
  • Verify row counts before trusting a joined total
  • Select only the columns and dates the question needs

Do not

  • Trust a query just because it ran without an error
  • Join tables on a key that repeats on both sides
  • Ask clients to run queries instead of reading a report

Questions people ask about this

Do marketers need to learn SQL?

Not everyone, but it repays anyone who works with data across more than one platform. The subset that matters is small: choosing columns, filtering by date and condition, grouping and summing. That is enough to answer questions no interface offers. Deeper work — window functions, complex joins, performance tuning — can stay with whoever builds the pipelines.

Why does my SQL result look too high?

Very often it is a join on a key that is not unique. If a single row in one table matches several rows in the other, that row is counted more than once and every total inflates. Check how many rows the query returns before and after the join, and confirm the key you are matching on identifies one record on at least one side.

Is SQL the same in every tool?

The core is shared: selecting, filtering, grouping and joining look much the same everywhere. Individual systems differ in their functions, especially around dates, text handling and JSON, so a query written for one warehouse may need small edits for another. Learning one dialect makes the others quick to pick up rather than starting again.

Related terms

Found this useful?

Share it, or ask an AI to summarise it

Back to the glossary

Knowing the term is the easy part

Applying it to your own site and budget is the work. Book a call and I will tell you what actually applies to you.