Prod Squad

SQL basics every PM should know

The handful of SQL concepts that let you answer your own questions and talk credibly with data teams.

6 min readAll levels#sql#data#queries#analytics
Ask about this lesson
On this page

You don't need to be a data engineer, but PMs who can write simple SQL move faster: they answer their own questions, sanity-check dashboards, and have sharper conversations with data scientists. Some PM interviews, especially at data-heavy companies, include a light SQL or data exercise.

Why interviewers ask this

Interviewers want to know if you can get to data without waiting a week for an analyst, and whether you understand how metrics are actually computed. A PM who knows that "daily active users" is a COUNT(DISTINCT user_id) with a date filter is far less likely to misread a dashboard. In interviews, you may be asked to describe a query, or write one on a whiteboard.

The framework

The core building blocks

SELECT   column(s), aggregate(...)
FROM     table
JOIN     other_table ON matching_key
WHERE    row filters
GROUP BY grouping column(s)
HAVING   filters on aggregates
ORDER BY column DESC
LIMIT    n;
  1. SELECT / FROM: which columns, from which table.
  2. WHERE: filter rows, e.g. WHERE event_date >= '2026-01-01' AND country = 'IN'.
  3. Aggregates: COUNT(*), COUNT(DISTINCT user_id), SUM(amount), AVG(amount).
  4. GROUP BY: aggregate per group, such as orders per day or users per country.
  5. JOIN: combine tables on a key. INNER JOIN keeps matches only; LEFT JOIN keeps all rows from the left table, even without a match. That's useful for finding users who didn't do something.
  6. HAVING: filter after aggregation, e.g. users with more than 5 orders.
  7. ORDER BY / LIMIT: sort and take the top results.

Concepts PMs should understand

  • Distinct counts: users vs. events. 1,000 events might be 50 users.
  • Date logic: daily, weekly and monthly grouping, and time zones.
  • Cohorts: group users by signup week, then measure their behaviour over time.
  • NULLs: missing values behave strangely in filters and averages.
  • Common pitfalls: double-counting after joins (one user, many orders), and filtering in WHERE versus HAVING.

A useful habit

Before you trust any number you pulled yourself, check it two ways: compare the result against an existing dashboard, and look at a handful of raw rows to make sure the data means what you think it means. Most SQL mistakes PMs make aren't syntax errors; they're queries that run perfectly and answer a slightly different question.

Worked example

Question: "We have a users table (user_id, signup_date, country) and an orders table (order_id, user_id, order_date, amount). How would you find the percentage of users who signed up in January and placed at least one order within 7 days?"

Sample answer:

"I'd start with all January sign-ups, left-join to their orders within seven days of signing up, then compute the share with at least one order.

SELECT
  COUNT(DISTINCT u.user_id) AS signups,
  COUNT(DISTINCT o.user_id) AS converted,
  ROUND(100.0 * COUNT(DISTINCT o.user_id) / COUNT(DISTINCT u.user_id), 1) AS pct_converted
FROM users u
LEFT JOIN orders o
  ON o.user_id = u.user_id
 AND o.order_date BETWEEN u.signup_date AND u.signup_date + INTERVAL '7 days'
WHERE u.signup_date >= '2026-01-01'
  AND u.signup_date <  '2026-02-01';

A few things to point out:

  • I use a LEFT JOIN so users with no orders stay in the denominator. An inner join would only keep buyers and give 100%.
  • The seven-day condition sits in the join, not the WHERE clause. Putting it in WHERE would silently drop users without orders.
  • COUNT(DISTINCT o.user_id) counts converted users, not orders, so a user with three orders counts once.

As a follow-up, I'd group by country or signup week to see whether conversion differs. That's where product insight usually comes from."

Common mistakes

  • Counting events instead of users (COUNT(*) vs. COUNT(DISTINCT user_id)).
  • Using INNER JOIN when you need to keep non-matching rows.
  • Filtering a LEFT JOIN in WHERE, which turns it back into an inner join.
  • Ignoring time zones and date boundaries.
  • Pretending to know more SQL than you do. Interviewers value clear logic over syntax.

Interviewer tips

What "great" sounds like:

  • "Let me first say the logic in plain English, then write the query."
  • "I'll use a LEFT JOIN so non-buyers stay in the denominator."
  • "I'm counting distinct users, not orders."
  • "I'd sanity-check this against the dashboard number."
  • Being honest: "I'd double-check the date function syntax for our warehouse, but the logic is..."

Practice questions

Answer one in a mock interview and get graded instantly.

  1. 1.How would you calculate the share of January sign-ups who ordered within 7 days, using a users table and an orders table?

    Practice this →
  2. 2.How would you write a query to find weekly active users for the last 8 weeks?

    Practice this →
  3. 3.A dashboard shows conversion at 120%. What might be wrong with the underlying query?

    Practice this →

Finished reading?