The most comprehensive guide to SQL interview questions for data analyst, data engineer, and backend engineering roles -- with solutions and explanations.
SQL fluency is expected at most tech companies for any role that touches data -- which, in 2026, is nearly every role. Data analysts, data engineers, backend engineers, product managers, and business analysts all face SQL rounds.
The good news: SQL interviews follow predictable patterns. This guide covers every pattern you'll encounter.
| Role | SQL Depth Required |
|---|---|
| Business Analyst | JOINs, GROUP BY, HAVING, subqueries |
| Data Analyst | All of above + window functions, CTEs, date functions |
| Data Engineer | All of above + query optimization, indexing, partitioning |
| Backend Engineer | Schema design, indexing, EXPLAIN, transaction isolation |
| Product Manager | Basic SELECT, filtering, aggregation (some companies) |
You will be asked about JOINs in every SQL interview.
| JOIN Type | Returns |
|---|---|
| INNER JOIN | Rows where the condition matches in both tables |
| LEFT JOIN | All rows from left table, matching rows from right (NULLs for no match) |
| RIGHT JOIN | All rows from right table, matching rows from left |
| FULL OUTER JOIN | All rows from both tables |
| CROSS JOIN | Cartesian product (every combination) |
Classic interview question:
"Find all customers who have never placed an order."
`sql
SELECT c.customer_id, c.name
FROM customers c
LEFT JOIN orders o ON c.customer_id = o.customer_id
WHERE o.order_id IS NULL;
`
"Find the top 5 products by total revenue in each category."
`sql
WITH ranked AS (
SELECT
category,
product_id,
SUM(revenue) AS total_revenue,
RANK() OVER (PARTITION BY category ORDER BY SUM(revenue) DESC) AS rank
FROM sales
GROUP BY category, product_id
)
SELECT category, product_id, total_revenue
FROM ranked
WHERE rank <= 5;
`
Window functions are the most common differentiator between junior and mid/senior SQL candidates.
Key window functions:
| Function | Use Case |
|---|---|
| ROW_NUMBER() | Unique sequential number per partition |
| RANK() | Ranking with gaps (1, 1, 3) |
| DENSE_RANK() | Ranking without gaps (1, 1, 2) |
| LAG() / LEAD() | Access previous/next row's value |
| SUM() OVER | Running total |
| AVG() OVER | Moving average |
Classic window function question:
"Find users who made a purchase on two consecutive days."
`sql
WITH consecutive AS (
SELECT
user_id,
purchase_date,
LAG(purchase_date, 1) OVER (PARTITION BY user_id ORDER BY purchase_date) AS prev_date
FROM purchases
)
SELECT DISTINCT user_id
FROM consecutive
WHERE purchase_date = prev_date + INTERVAL '1 day';
`
"Calculate the month-over-month revenue growth rate."
`sql
WITH monthly AS (
SELECT
DATE_TRUNC('month', order_date) AS month,
SUM(amount) AS revenue
FROM orders
GROUP BY 1
),
with_prev AS (
SELECT
month,
revenue,
LAG(revenue) OVER (ORDER BY month) AS prev_revenue
FROM monthly
)
SELECT
month,
revenue,
ROUND(100.0 * (revenue - prev_revenue) / prev_revenue, 2) AS mom_growth_pct
FROM with_prev
WHERE prev_revenue IS NOT NULL;
`
Interviewers for data engineering roles often ask:
Key concepts:
NULL behavior trips up many candidates:
Google (data analyst): Complex aggregations, cohort analysis, funnel queries.
Amazon (data science): Retention queries, A/B test analysis, window functions.
Facebook/Meta: Graph queries, social network analysis patterns.
Flipkart/Amazon India: Revenue analysis, customer segmentation, order funnel queries.
Startups: Practical business questions -- user retention, revenue attribution, event funnel.
Do I need to know database-specific SQL syntax?
Know ANSI SQL well. For your target role's common database (BigQuery, Snowflake, PostgreSQL, MySQL), learn the 5-10 most common syntax differences.
Should I practice writing SQL without an IDE?
Yes. Interviews are often in a plain text editor or whiteboard tool. Practice writing without autocomplete.
What if I don't know the answer?
Think aloud. SQL interviewers often care about problem-solving approach as much as final syntax.
Ready to apply what you've learned?
Build your resume with AI-powered suggestions and real-time ATS scoring.
Create Your Resume - Free