Top 10 SQL Interview Questions Every Data Analyst Must Master

SQL interviews for data analyst roles usually test joins, grouping, window functions, and real-world data thinking. The strongest preparation comes from practicing both question types and business scenarios, not just syntax.

Why SQL matters

Companies use SQL to check whether you can retrieve, clean, and summarize data correctly. Many interviewers also expect you to explain your logic clearly, especially for scenario-based questions like duplicates, rankings, and trend analysis.

Top 10 questions

  1. What is the difference between WHERE and HAVING?
    WHERE filters rows before grouping, while HAVING filters after aggregation.
  2. How do you find duplicate rows in a table?
    Group by the key columns and use HAVING COUNT(*) > 1.
  3. What is the difference between INNER JOIN and LEFT JOIN?
    INNER JOIN returns matching rows only, while LEFT JOIN keeps all left table rows plus matches from the right.
  4. How do you get the second highest salary?
    Use a subquery, window function, or sort with LIMIT/OFFSET depending on the database.
  5. What are window functions?
    They let you compute values across a related set of rows without collapsing the result set.
  6. What is the difference between GROUP BY and DISTINCT?
    GROUP BY is used for aggregation, while DISTINCT removes duplicate rows from the output.
  7. How do you identify records with NULL values?
    Use IS NULL or IS NOT NULL; never compare NULL with =.
  8. What is a self-join?
    A self-join joins a table to itself, often used for manager-employee or hierarchy data.
  9. How do you calculate running totals?
    Use SUM() OVER (ORDER BY …) to create a cumulative result.
  10. How do you approach a business question in SQL?
    Start by identifying the metric, filter the right rows, aggregate correctly, and check the result against the business goal.

Quick prep tip

Practice each question with one example query and one explanation in plain English. That way, even if the interviewer changes the wording, your answer still sounds confident and structured.

Leave a Comment

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

Scroll to Top