SQL Interview Questions for Data Analysts: GROUP BY, HAVING and JOINs
Crack the SQL round for data analyst jobs
Understand the SQL questions every analyst interview asks, from WHERE and GROUP BY to JOINs and NULLs, and explain your queries with confidence.
SQL (Structured Query Language) is the language you use to ask a database questions. Almost every data analyst interview has a SQL round, whether it is a campus placement, an online test or a live screen-share. Interviewers use it to check if you can turn a business question into correct data.
In this lab you will learn the core ideas behind the most common SQL questions: filtering, grouping, joining tables and handling missing values. You will also practise explaining a query out loud, which is often what decides the round.
The big idea: SQL runs in a different order
You write SELECT first, but the database works in three stages.
Spot the difference
Question: “What is the difference between WHERE and HAVING?” Switch between the two answers.
Quick concept check
Tap each card to flip it and see the correct answer.
Key concepts, explained simply
Each idea starts with an everyday picture, then the correct SQL meaning.
-- Top 3 cities by delivered revenue since Jan 2025 (100+ orders)
SELECT c.city,
COUNT(*) AS orders,
SUM(o.amount) AS revenue
FROM orders o
JOIN customers c ON o.customer_id = c.id
WHERE o.status = 'Delivered'
AND o.order_date >= '2025-01-01'
GROUP BY c.city
HAVING COUNT(*) >= 100
ORDER BY revenue DESC
LIMIT 3;
Explain a query you wrote
Fill the blanks. Your answer writes itself on the right.
Model answers to three classic SQL questions
These come up again and again. Learn the idea, not just the query.
“I would use a subquery: SELECT MAX(salary) FROM employees WHERE salary < (SELECT MAX(salary) FROM employees). It finds the top salary, then the highest one below it. For the Nth highest salary, I prefer DENSE_RANK() OVER (ORDER BY salary DESC) and pick rank N, because it handles ties correctly.”
“To find duplicate emails, I group by email and keep groups with more than one row: SELECT email, COUNT(*) FROM users GROUP BY email HAVING COUNT(*) > 1. Before removing anything, I would confirm with the team which copy to keep, then use ROW_NUMBER() to mark the extra rows.”
“DELETE removes chosen rows using a WHERE clause, and it can be rolled back inside a transaction. TRUNCATE removes all rows at once and is usually faster; in MySQL and SQL Server it also resets the auto-increment counter. DROP removes the whole table, including its structure. As an analyst, I would be very careful running any of these on live data.”
Four SQL mistakes that cost you the round
Test yourself
Question 1 of 5
Rehearse before the real thing
Pick one sample question, press start and explain your query out loud. The ring turns amber at 60 seconds and red at 90.
- 1WHERE rows, HAVING groups
- 2Know INNER vs LEFT JOIN
- 3Use IS NULL, never = NULL
- ★Say your plan before you type
Screenshot it. Save it. Share it.
Keep this card on your phone and look at it five minutes before your interview.
Quick answers
Should I learn MySQL or PostgreSQL for analyst jobs?
Either is fine. Most interview questions use standard SQL that works in both. Learn one well and note small differences, like LIMIT in MySQL and PostgreSQL versus TOP in SQL Server.
What do fresher SQL rounds usually cover?
Mostly SELECT, WHERE, GROUP BY, HAVING, JOINs and aggregate functions. Many companies also add a window function or CTE question, so practise those too.
Do I really need window functions?
For many analyst roles, yes, at a basic level. Know ROW_NUMBER, RANK and DENSE_RANK, and running totals with SUM() OVER (ORDER BY date).
What if I cannot run the query in the interview?
Many first rounds use a shared doc or simple editor. Write clean, indented SQL, explain each step and walk through a tiny sample of data to show the output.

One Comment