Home › Blog

SQL Interview Questions for Data Analyst Freshers (2026): 21 Questions + 5 Must-Practise Queries

Jyoti · 17 Nov 2026 · Career & Interview Prep

SQL Interview Questions for Data Analyst Freshers (2026): 21 Questions + 5 Must-Practise Queries

Key Takeaways

  • Most SQL interview questions for data analyst freshers come from five areas: basics (SELECT, WHERE, keys), JOINs, GROUP BY with HAVING, subqueries and CTEs, and window functions like RANK and ROW_NUMBER.
  • Interviewers care less about definitions and more about whether you can write a correct query on a small table, explain it out loud and handle NULLs and duplicates.
  • A handful of classic tasks come up again and again: second highest salary, finding duplicates, top N per group, running totals and month-wise counts. Practise each until you can write it without help.
  • Read every question twice, ask about the table columns, write the query step by step and check it on a sample row before you say "done".
  • Four weeks of daily practice on real datasets is enough for most freshers to clear the SQL round with confidence.

These are the SQL interview questions for data analyst freshers that Indian interviewers ask most often, with short answers and working queries you can practise today. The SQL round usually tests JOINs, GROUP BY, subqueries and window functions on a simple table such as employees, orders or customers, so this guide is organised the same way.

If you are still deciding whether data analytics is right for you, read our guide on the data analyst fresher salary in India first. For the non-technical part of the interview, our list of HR interview questions for freshers covers the HR round.

Table of Contents

  1. What does the SQL round for a data analyst fresher look like?
  2. Basic SQL interview questions for data analyst freshers
  3. JOIN questions: the most asked topic
  4. GROUP BY, HAVING and aggregate questions
  5. Subqueries and CTE questions
  6. Window function questions (RANK, DENSE_RANK, ROW_NUMBER)
  7. 5 practical query tasks you must practise
  8. 4-week SQL preparation plan
  9. Common mistakes in the SQL round
  10. How My Career Solution helps

What does the SQL round for a data analyst fresher look like?

Most companies hiring fresher data analysts test SQL in one of three ways: an online test with multiple-choice and query-writing questions, a live coding round where you share your screen and write queries, or a take-home task with a small dataset. Many hiring processes also include an Excel or Power BI/Tableau round and an HR round, but SQL is usually the round that decides whether you move ahead.

SQL interview round for data analyst freshers: the usual stages

In a live round, the interviewer usually shows you one or two tables and asks four to six questions that get harder step by step. A typical sequence looks like this:

  1. A warm-up: select rows with a filter and sort them.
  2. An aggregate: count or sum by a category using GROUP BY.
  3. A JOIN between two tables, often with a twist like "include customers with no orders".
  4. A ranking or "top N per group" question using a window function.
  5. A follow-up such as "what if there are ties?" or "what if the column has NULLs?"

They are watching how you think, not only the final answer. Talk through your logic as you write.

Basic SQL interview questions for data analyst freshers

These questions open almost every interview. Keep your answers short and give a one-line example.

1. What is the difference between WHERE and HAVING?

WHERE filters rows before grouping. HAVING filters groups after GROUP BY, so it can use aggregates like COUNT or SUM. Example: WHERE city = 'Pune' removes rows; HAVING COUNT(*) > 5 removes groups.

2. What is the difference between DELETE, TRUNCATE and DROP?

DELETE removes selected rows and can use a WHERE clause. TRUNCATE removes all rows but keeps the table structure. DROP removes the table itself, including its structure.

3. What is a primary key and a foreign key?

A primary key uniquely identifies each row in a table and cannot be NULL. A foreign key is a column in one table that points to the primary key of another table, which is how tables are linked for JOINs.

4. What is the difference between UNION and UNION ALL?

UNION combines results and removes duplicate rows. UNION ALL keeps every row, including duplicates, and is faster because it skips the duplicate check.

5. How does SQL treat NULL?

NULL means "unknown", so salary = NULL never matches. Use IS NULL or IS NOT NULL. COUNT(*) counts all rows, while COUNT(column) skips NULLs. Use COALESCE(column, 0) to replace NULL with a default value.

6. What is the order of execution of a SQL query?

The logical order is FROM and JOIN, then WHERE, GROUP BY, HAVING, SELECT, DISTINCT, ORDER BY and finally LIMIT. This is why you cannot use a SELECT alias inside WHERE in most databases.

7. What is the difference between CHAR and VARCHAR?

CHAR stores a fixed length and pads shorter values with spaces. VARCHAR stores only the characters you enter, up to the maximum length.

8. What is an index and why is it used?

An index is a lookup structure that helps the database find rows faster, much like the index of a book. It speeds up reads on filtered or joined columns but adds a small cost to inserts and updates.

JOIN questions: the most asked topic

If you prepare only one topic well, make it JOINs. Interviewers ask about them in almost every SQL round because real analyst work means combining tables every day.

SQL joins explained for data analyst interviews: INNER, LEFT, RIGHT and FULL OUTER JOIN

9. Explain INNER, LEFT, RIGHT and FULL OUTER JOIN.

  • INNER JOIN returns only rows that match in both tables.
  • LEFT JOIN returns all rows from the left table and matching rows from the right; non-matches show NULL.
  • RIGHT JOIN is the mirror of LEFT JOIN.
  • FULL OUTER JOIN returns all rows from both tables, with NULLs where there is no match.

10. Find customers who have never placed an order.

This is the classic LEFT JOIN question:

SELECT c.customer_id, c.name
FROM customers c
LEFT JOIN orders o ON o.customer_id = c.customer_id
WHERE o.order_id IS NULL;

11. What is a self join? Give an example.

A self join joins a table to itself. The common example is finding each employee's manager from one employees table:

SELECT e.name AS employee, m.name AS manager
FROM employees e
LEFT JOIN employees m ON e.manager_id = m.emp_id;

12. Why did my JOIN return more rows than expected?

Because the join key is not unique on one side. If one customer has three orders, joining customers to orders gives three rows for that customer. Always check whether the key is one-to-one or one-to-many before you aggregate after a JOIN.

JOIN type Rows returned Typical analyst use
INNER JOIN Only matches Orders with valid product details
LEFT JOIN All left + matches Customers with or without orders
FULL OUTER JOIN Everything from both Comparing two lists for gaps
SELF JOIN Table joined to itself Employee-manager, same-day comparisons

GROUP BY, HAVING and aggregate questions

Analysts summarise data all day, so expect at least one GROUP BY question.

13. Count employees in each department and show only departments with more than 5 people.

SELECT department, COUNT(*) AS headcount
FROM employees
GROUP BY department
HAVING COUNT(*) > 5
ORDER BY headcount DESC;

14. What is the difference between COUNT(*), COUNT(column) and COUNT(DISTINCT column)?

COUNT(*) counts all rows. COUNT(column) counts rows where that column is not NULL. COUNT(DISTINCT column) counts unique non-NULL values, for example the number of unique customers who ordered.

15. Find month-wise total sales.

SELECT DATE_FORMAT(order_date, '%Y-%m') AS month,
       SUM(amount) AS total_sales
FROM orders
GROUP BY DATE_FORMAT(order_date, '%Y-%m')
ORDER BY month;

Mention that the date function differs by database: DATE_FORMAT in MySQL, TO_CHAR or DATE_TRUNC in PostgreSQL, FORMAT in SQL Server. Interviewers like it when you know this.

Subqueries and CTE questions

16. What is a subquery? What is a correlated subquery?

A subquery is a query inside another query. A correlated subquery uses a value from the outer query, so it runs once per outer row. Example: employees who earn more than their department average.

SELECT e.name, e.salary, e.department
FROM employees e
WHERE e.salary > (
  SELECT AVG(salary) FROM employees
  WHERE department = e.department
);

17. What is a CTE and why use it?

A CTE (Common Table Expression) is a named temporary result written with WITH. It makes long queries easier to read and lets you build the answer step by step, which is exactly how you should solve interview questions.

WITH dept_avg AS (
  SELECT department, AVG(salary) AS avg_sal
  FROM employees GROUP BY department
)
SELECT e.name, e.salary, d.avg_sal
FROM employees e
JOIN dept_avg d ON d.department = e.department
WHERE e.salary > d.avg_sal;

18. What is the difference between IN and EXISTS?

IN checks whether a value is in a list returned by a subquery. EXISTS checks whether the subquery returns any row at all and stops at the first match. Also mention the NULL trap: NOT IN returns no rows if the subquery list contains a NULL, so NOT EXISTS is safer.

Window function questions (RANK, DENSE_RANK, ROW_NUMBER)

Window functions separate prepared candidates from the rest. They calculate a value across a set of rows without collapsing them like GROUP BY does.

RANK vs DENSE_RANK vs ROW_NUMBER in SQL with a salary example

19. What is the difference between RANK, DENSE_RANK and ROW_NUMBER?

For salaries 90k, 80k, 80k, 70k:

Salary ROW_NUMBER RANK DENSE_RANK
90,000 1 1 1
80,000 2 2 2
80,000 3 2 2
70,000 4 4 3

ROW_NUMBER always gives unique numbers. RANK gives ties the same number and skips the next one. DENSE_RANK gives ties the same number without gaps.

20. Find the top 3 earners in each department.

WITH ranked AS (
  SELECT name, department, salary,
         DENSE_RANK() OVER (PARTITION BY department ORDER BY salary DESC) AS rnk
  FROM employees
)
SELECT name, department, salary
FROM ranked
WHERE rnk <= 3;

21. What do LAG and LEAD do?

LAG reads a value from the previous row and LEAD from the next row in the window order. Analysts use them for day-over-day or month-over-month change, for example amount - LAG(amount) OVER (ORDER BY month).

5 practical query tasks you must practise

These five come up so often that you should be able to write them from memory.

Task 1: Second highest salary

SELECT MAX(salary) AS second_highest
FROM employees
WHERE salary < (SELECT MAX(salary) FROM employees);

Also know the general version with DENSE_RANK() ... WHERE rnk = N, because the follow-up is usually "now find the Nth highest".

Task 2: Find duplicate emails

SELECT email, COUNT(*) AS times
FROM users
GROUP BY email
HAVING COUNT(*) > 1;

Task 3: Delete duplicates but keep one row

WITH d AS (
  SELECT id, ROW_NUMBER() OVER (PARTITION BY email ORDER BY id) AS rn
  FROM users
)
DELETE FROM users WHERE id IN (SELECT id FROM d WHERE rn > 1);

Say that you would first run it as a SELECT to check which rows will go. Interviewers notice this kind of care.

Task 4: Running total of sales

SELECT order_date, amount,
       SUM(amount) OVER (ORDER BY order_date) AS running_total
FROM orders;

Task 5: Percentage share of each category

SELECT category,
       SUM(amount) AS sales,
       ROUND(100.0 * SUM(amount) / SUM(SUM(amount)) OVER (), 2) AS pct_share
FROM orders
GROUP BY category;

4-week SQL preparation plan

You do not need an expensive course to clear a fresher SQL round. You need daily practice on real tables and the habit of explaining your query.

4-week SQL interview preparation plan for data analyst freshers

  1. Week 1, basics: SELECT, WHERE, ORDER BY, LIMIT, DISTINCT, NULL handling, CASE WHEN. Install MySQL or PostgreSQL locally, or use a free online editor, and load a sample database.
  2. Week 2, JOINs and GROUP BY: all JOIN types, self joins, GROUP BY with HAVING, date functions. Solve 3-5 problems a day on a free practice site.
  3. Week 3, subqueries, CTEs and window functions: correlated subqueries, EXISTS, RANK, DENSE_RANK, ROW_NUMBER, LAG, LEAD, running totals.
  4. Week 4, mock interviews and a project: time yourself on 5-question sets, explain each query out loud, and build one small analysis project (for example sales by month and region) that you can show on your resume and GitHub.

Put that project on your resume with a one-line result. Our guides on making an ATS-friendly resume for freshers and writing a resume summary for freshers show how to phrase it so recruiters find the SQL keyword.

Common mistakes in the SQL round

  • Jumping straight into code. First confirm the columns, the expected output and how ties or NULLs should be handled.
  • Using WHERE with an aggregate. WHERE COUNT(*) > 5 fails; it belongs in HAVING.
  • Selecting columns that are not in GROUP BY. Many databases reject it, and the ones that allow it give unpredictable values.
  • Ignoring duplicates after a JOIN. Sums and counts become too high when one side has many matching rows.
  • Forgetting NULL behaviour. NOT IN with NULLs and = NULL are the two classic traps.
  • Staying silent. If you are stuck, explain what you are trying. A partly correct query with clear reasoning often scores better than silence.

How My Career Solution helps

Clearing the SQL round only matters once you get the interview call. That is the part My Career Solution (MCS) handles. Our team applies to relevant data analyst jobs and companies on your behalf, sends your resume to recruiters and tracks replies, so you can spend your time practising SQL instead of filling forms.

  • Free start: when you sign up and complete your profile, MCS applies to 5 companies for you for free.
  • Guaranteed interview calls: paid packages come with a guaranteed number of interview calls based on the package you choose. See the details on the packages page.
  • Company research: browse hiring companies on the companies page before your interview.

Want more interview prep? Read how to answer "tell me about yourself" and how to get interview calls as a fresher, or browse all guides on the MCS blog.

Ready to turn your SQL prep into interviews? See MCS packages and let us apply to data analyst roles for you, while you practise the queries above.

Frequently asked questions

What SQL topics are asked in a data analyst fresher interview?

Mostly basics (SELECT, WHERE, keys, NULL), JOINs, GROUP BY with HAVING, subqueries and CTEs, and window functions such as RANK, DENSE_RANK, ROW_NUMBER, LAG and LEAD. Practical tasks like second highest salary, duplicates and running totals are very common.

How much SQL is enough for a data analyst fresher job?

You should be able to write JOIN, GROUP BY, subquery and window function queries on unfamiliar tables without help, and explain them. Database administration topics like stored procedures or tuning are rarely needed at fresher level.

Which database should I practise on, MySQL or PostgreSQL?

Either is fine because the core SQL is the same. MySQL is common in Indian tutorials and PostgreSQL has fuller window function support. Learn one well and know the small differences in date functions.

How long does it take to prepare SQL for interviews?

With one to two hours of daily practice, most freshers are interview-ready in about four weeks: basics, then JOINs and GROUP BY, then window functions, then mock interviews.

Is SQL enough to get a data analyst job as a fresher?

SQL is the most important skill, but most roles also expect Excel and one dashboard tool like Power BI or Tableau, plus basic statistics. A small project that uses all of them makes your resume much stronger.