Interview

SQL Interview Questions for Data Analysts (With Answers)

April 11, 2026 6 min read 0 comments

The Most Predictable Interview Section

If Power BI questions test how you build, SQL questions test how you think. The good news: analyst-level SQL interviews are remarkably predictable. They probe the same core patterns — basic queries, joins, aggregation, window functions — over and over. Prepare these and you'll walk into any analyst SQL round with confidence.

Q1. What's the difference between WHERE and HAVING?

WHERE filters rows before aggregation; HAVING filters groups after aggregation. You can't use an aggregate in WHERE (WHERE SUM(x) > 10 is invalid), but you can in HAVING. In practice: filter raw rows with WHERE for performance, use HAVING for conditions on aggregated results.

Q2. Explain the types of joins with an example.

INNER JOIN returns matching rows from both tables. LEFT JOIN returns all rows from the left table plus matches (NULLs where no match). RIGHT JOIN is the mirror. FULL OUTER JOIN returns all rows from both sides. SELF JOIN joins a table to itself (e.g., employees to managers). CROSS JOIN pairs every row with every row — rarely needed, dangerous if forgotten.

Q3. How do you find duplicate records?

Group by the columns that should be unique and count: SELECT email, COUNT(*) FROM users GROUP BY email HAVING COUNT(*) > 1. For full-row duplicates, use GROUP BY all columns or the ROW_NUMBER() OVER (PARTITION BY … ) technique to identify and optionally delete one of each.

Q4. What is the difference between a subquery and a CTE?

A subquery is a query nested inside another query (in SELECT, FROM or WHERE). A CTE (WITH clause) names an intermediate result set that you can reference, often multiple times, above the main query. CTEs are more readable for complex logic and are the modern preferred pattern for multi-step analysis.

Q5. Explain window functions and give an example.

Window functions compute values across a set of rows related to the current row without collapsing the result — unlike GROUP BY. Examples: ROW_NUMBER() OVER (PARTITION BY category ORDER BY sales DESC) to rank products within each category, or SUM(sales) OVER (PARTITION BY region ORDER BY month) for a running total.

Q6. How do you get the top 3 salaries per department?

Use a window function: WITH ranked AS (SELECT *, ROW_NUMBER() OVER (PARTITION BY dept_id ORDER BY salary DESC) AS rn FROM employees) SELECT * FROM ranked WHERE rn <= 3. This preserves ties handling options (ROW_NUMBER vs RANK) and is a classic interviewer favorite.

Q7. What's the difference between RANK, DENSE_RANK and ROW_NUMBER?

ROW_NUMBER assigns a unique sequential number (1,2,3) regardless of ties. RANK gives tied rows the same number and skips the next (1,1,3). DENSE_RANK gives tied rows the same number without skipping (1,1,2). Choose based on whether you want unique rows or meaningful ties.

Q8. What is a left join where the right key is NULL useful for?

The "LEFT JOIN … WHERE right.key IS NULL" pattern returns rows from the left table with no match in the right — perfect for finding orphaned records, customers who never ordered, or products with no sales. It's the standard anti-join technique.

Q9. How would you write a query for month-over-month growth?

Aggregate sales by month, then use LAG to reference the previous month: WITH monthly AS (SELECT DATE_TRUNC('month', order_date) AS month, SUM(amount) AS total FROM orders GROUP BY 1), growth AS (SELECT month, total, LAG(total) OVER (ORDER BY month) AS prev FROM monthly) SELECT month, total, (total – prev) / prev AS growth FROM growth. LAG/LEAD for comparisons is exactly what interviewers want to see.

Q10. What is query folding in the Power BI context?

Query folding is when Power Query pushes transformation steps back to the source database as SQL, so only the processed result is returned instead of pulling raw data into memory. It's vital for performance with large tables — and a favourite crossover question because it shows SQL awareness inside the Power BI world.

SQL interviews reward clean thinking. Write your answer in plain words first, then translate to SQL — the logic is what's being tested.

The Thinking Behind Every Answer

These ten questions share a secret: each one tests a habit, not a fact. The WHERE vs HAVING question tests whether you think about when aggregation happens. The joins question tests whether you can visualize relationships between data. The duplicates question tests whether you can express "what should be unique" precisely. The window-function questions test whether you understand rows in relation to other rows. When you answer, name the thinking: "this is an anti-join, so I'll use a LEFT JOIN with a NULL check" — that language signals someone who reasons in patterns, not someone who memorized answers.

Interviewers also watch how you handle the moment you don't know something. The professional response is to think aloud: "I'm not sure of the exact syntax, but the approach would be…" — stated logic you can reason through beats silence or a wrong confident guess. Every strong analyst has answered an unknown question by reasoning from first principles; that's the skill this round is actually testing.

How to Practice Like You're Interviewing

  • Rewrite each answer in plain words before looking at the model answer.
  • Type the SQL, don't just read it — muscle memory matters.
  • Time yourself: a full answer in under two minutes.
  • Explain your answer out loud as if the interviewer can't see the screen.
  • Create your own variations: change the table names, change the question slightly, solve again.

A week of this practice, twenty minutes a day, and the SQL round becomes the round you look forward to. That's the level of calm interviewers reward — and it's exactly what mock-interview rehearsal builds in candidates before they ever sit in the real room.

One last note: interviewers love to see you take a follow-up the "wrong" way and recover. If the interviewer says "what if the data is different than you assumed?", the strongest response is to state the new assumption and reason again from there — showing adaptability, not memorization. Practising recovery beats practising perfection, and it's the quality that finally separates the answer robots from the analysts.

Master these ten questions and their patterns, and you'll notice something: the SQL round stops being a gate and becomes an opportunity to display the precise, structured thinking that every data role rewards.

Limited Seats — Next Batch Starting Soon

Walk Into Interviews With Confidence

Join the Power BI Master Course at ₹4,999 — live classes, 4 projects, mock interviews and placement support.

100% money-back guarantee if you don’t find value in the first class

A
admin Power BI Trainer & Content Lead at Power BI Course

Helping professionals and freshers master Power BI, data analytics and business intelligence through practical, job-focused training.

Share this guide:

Leave a Reply

Your email address will not be published. Required fields are marked *

Our Top Power BI Course in India

Looking for Power BI training in a specific city? Explore our city-wise Power BI Course pages to find course information, training details, curriculum, practical learning approach, and career guidance for your location.

Power BI Course Power BI Course Power BI Course
Power BI Course in Mumbai Power BI Course in Delhi Power BI Course in Hyderabad
Power BI Course in Pune Power BI Course in Chennai Power BI Course in Kolkata
Power BI Course in Ahmedabad Power BI Course in Jaipur Power BI Course in Lucknow
Power BI Course in Kanpur Power BI Course in Nagpur Power BI Course in Indore
Power BI Course in Thane Power BI Course in Bhopal Power BI Course in Visakhapatnam
Power BI Course in Bangalore Power BI Course in Patna Power BI Course in Vadodara
Power BI Course in Ghaziabad Power BI Course in Ludhiana Power BI Course in Agra
Power BI Course in Nashik Power BI Course in Faridabad Power BI Course in Meerut
Power BI Course in Rajkot Power BI Course in Kalyan-Dombivali Power BI Course in Vasai-Virar
Power BI Course in Varanasi Power BI Course in Srinagar Power BI Course in Aurangabad
Power BI Course in Dhanbad Power BI Course in Amritsar Power BI Course in Navi Mumbai
Power BI Course in Allahabad Power BI Course in Ranchi Power BI Course in Howrah
Power BI Course in Coimbatore Power BI Course in Jabalpur Power BI Course in Gwalior
Power BI Course in Vijayawada Power BI Course in Jodhpur Power BI Course in Madurai
Power BI Course in Raipur Power BI Course in Kota Power BI Course in Guwahati
Power BI Course in Chandigarh Power BI Course in Solapur Power BI Course in Hubballi-Dharwad
Power BI Course in Tiruchirappalli Power BI Course in Bareilly Power BI Course in Mysore
Power BI Course in Tiruppur Power BI Course in Gurgaon Power BI Course in Aligarh
Power BI Course in Jalandhar Power BI Course in Bhubaneswar Power BI Course in Salem
WhatsApp Call NowEnroll @ ₹4,999