Top 50 SQL Interview Questions for Data Analysts (2026 Update)
Most SQL interview lists just dump questions with no structure. This one follows the same stage progression as our SQL roadmap — fundamentals, joins, subqueries/CTEs, window functions, and reasoning/business questions — so you can practice in the order that actually builds fluency, then use the full list as a final review pass.
Fundamentals (Questions 1–12)
What's the difference between WHERE and HAVING?
Write a query to find the second-highest salary in an employees table.
What does DISTINCT do, and when would overusing it hide a data problem instead of solving one?
Explain the order SQL actually executes clauses in (not the order you write them in).
What's the difference between COUNT(*) and COUNT(column_name)?
Write a query returning all customers who haven't placed an order in the last 90 days.
What's the difference between UNION and UNION ALL, and why does the choice matter for performance?
How do you handle NULL values in a WHERE clause — why doesn't = NULL work?
Write a query to find duplicate rows in a table based on a subset of columns.
What's the difference between a primary key and a unique key?
Explain the difference between DELETE, TRUNCATE, and DROP.
Write a query to calculate the percentage each category contributes to total revenue.
Joins (Questions 13–22)
Explain the difference between INNER JOIN, LEFT JOIN, and FULL OUTER JOIN with a concrete example.
Write a query to find customers who have never placed an order, using a LEFT JOIN.
What happens to NULL values after a LEFT JOIN when there's no match on the right table?
Write a self-join query to find employees who report to a specific manager.
Can you join more than two tables in one query? Write an example with three tables.
What's the difference between an implicit join (comma syntax) and an explicit JOIN clause — why is the explicit form generally preferred?
Write a query that returns orders along with customer name and product name, joining three tables.
What's a Cartesian product, and how does a missing or incorrect join condition accidentally create one?
When would you use a RIGHT JOIN instead of restructuring the query as a LEFT JOIN?
Write a query to find products that have never been ordered.
Subqueries and CTEs (Questions 23–32)
What's the difference between a correlated and a non-correlated subquery?
Rewrite a deeply nested subquery using a CTE — why is the CTE version easier to read and debug?
Write a query using a subquery in the WHERE clause to find above-average-priced products.
Can a CTE reference itself? What's a recursive CTE used for?
Write a query using a subquery in the SELECT clause to show each order's total alongside the customer's running total.
What's the difference between a subquery in FROM versus a CTE — is there a real performance difference?
Write a query to find the top-selling product per category using a subquery.
When would you choose a temporary table over a CTE?
Write a CTE that filters, then joins the filtered result to another table.
Explain how EXISTS differs from IN, and when EXISTS performs better.
Window Functions (Questions 33–42)
What's the difference between RANK, DENSE_RANK, and ROW_NUMBER?
Write a query to find the top 3 highest-paid employees per department.
Explain what a window function's PARTITION BY clause does versus GROUP BY.
Write a query using LAG to compare each month's revenue to the previous month.
What's a running total, and how do you calculate one with a window function?
Write a query to calculate a 7-day moving average of daily sales.
Can you use a window function in a WHERE clause directly? Why or why not, and what's the workaround?
Write a query to find the first and last order date for each customer using window functions.
Explain the difference between ROWS and RANGE in a window frame clause.
Write a query calculating each employee's salary as a percentage of their department's total.
Reasoning and Business Questions (Questions 43–50)
A manager asks for "our best customers" — what clarifying questions do you ask before writing any query?
Write a query to calculate month-over-month revenue growth by category.
How would you identify customers at risk of churning using only order history data?
A query is running very slowly on a large table — what steps do you take to investigate before assuming you need an index?
Write a query to calculate a cohort retention rate (percentage of a signup month still active in month 2).
How do you decide whether a slow query needs a code fix versus an index versus a schema change?
Explain how you'd validate that a complex multi-join query's output is actually correct before presenting results.
Walk through how you'd approach a business question that requires combining data from a table you've never seen before.
How to Actually Use This List
Don't just read the answers — write and run every query against a real database, even a small local one, before checking your solution. Reading a correct answer and being able to produce it under interview pressure are different skills, and the gap between them is exactly what a live SQL screen tests.
For the reasoning questions (43–50), there's rarely one "correct" answer — interviewers are testing whether you ask clarifying questions and explain trade-offs, not whether you recite a memorized response. Practice narrating your thinking out loud, not just writing the final query silently.
Frequently Asked Questions
How many of these should I be able to answer before applying to jobs?
Comfortable fluency through the window functions section (question 42) covers the large majority of entry-to-mid-level analyst screens. The reasoning questions matter more as you target more senior roles.
Do interviews really ask window function questions for entry-level roles?
Increasingly, yes — window functions have become a common differentiator even at the entry level, so it's worth including in your prep even if you're targeting a junior title.
What if I get a SQL question about a schema I've never seen?
This is intentional on the interviewer's part — they're testing whether you ask about table relationships and column meanings before writing code, not whether you can guess correctly.
Should I practice on a specific database system (MySQL, PostgreSQL, etc.)?
Core syntax is nearly identical across systems for everything in this list — pick whichever free environment lets you start practicing today, and don't let choice-of-database become a reason to delay starting.
Bottom Line
SQL interviews test a narrower, more predictable set of patterns than they first appear to — fundamentals, joins, subqueries/CTEs, window functions, and business reasoning cover the overwhelming majority of what actually gets asked. Work through this list in order, write real queries rather than just reading answers, and you'll be prepared for most analyst-level SQL screens.