Blog › Interview Prep

SQL interview prep · Updated October 2026

SQL Interview Questions for Data Analysts (2026)

The SQL questions data analyst candidates face most often, from basics to window functions, with clear answers, query patterns and tips for live coding rounds.

✍️ Data Analytics Masters trainers

⏱ 12 min read

📅 Updated 13 October 2026

⚡ Short answer

Most analyst SQL rounds come down to two things: one JOIN with GROUP BY question and one window-function question, so build your practice around those two patterns first and then move to the wider data analyst interview questions.

SQL Interview Questions for Data Analysts

Topics by level

What gets tested at each level

Fresher interviews stay mostly in the first two rows; experienced roles go deeper.

Level

Topics

Typical for

Basic

SELECT, WHERE, ORDER BY, DISTINCT, aggregates, GROUP BY

All fresher roles

Intermediate

JOINs, HAVING, subqueries, CASE, CTEs, NULL handling

Data analyst, reporting analyst

Advanced

Window functions, running totals, execution plans, and writing the query that feeds a Power BI dashboard

Senior analyst, BI and SQL developer

Basic questions

Basic SQL interview questions

Get these perfect. Interviewers use them to judge your fundamentals in the first five minutes.

Basic

What is the order of execution of a SQL query?

Think of it as a pipeline: tables are joined first, rows are filtered next, groups form after that, and column names are given only at the end, so an alias like total_sales doesn’t exist yet when WHERE runs, but ORDER BY can use it. This is the kind of detail we drill in our SQL course in Hyderabad.

Basic

DELETE vs TRUNCATE vs DROP?

DELETE targets specific rows with WHERE, TRUNCATE empties the whole table but keeps its columns, and DROP removes the table itself, so in an interview say that you would run a SELECT with the same WHERE before any DELETE. You will find all three covered in the data analytics course syllabus.

Basic

What is a primary key vs a foreign key?

A primary key uniquely identifies each row; a foreign key references a primary key in another table to link them.

Basic

COUNT(*) vs COUNT(column)?

In a customers table with 1,000 rows and 120 blank emails, COUNT(*) returns 1,000 while COUNT(email) returns 880, and that gap is exactly how analysts spot missing data in beginner data analytics projects.

Basic

What does DISTINCT do?

It removes duplicate rows from the result based on the selected columns.

Basic

How do you handle NULLs?

Use IS NULL / IS NOT NULL to filter, and COALESCE to replace NULL with a default value. NULL = NULL is never true.

Intermediate questions

Intermediate SQL interview questions

This is where most data analyst interviews spend their time.

Joins

How does a LEFT JOIN create NULLs?

Put customers on the left and orders on the right: every customer stays in the result, and anyone who never ordered shows NULL in the order columns, so filtering on that NULL gives you a ready list of customers to win back. JOINs are a core step on the data analyst roadmap.

Joins

What is a self join?

Joining a table to itself with aliases, for example to match employees with their managers in the same table.

Grouping

Find departments with more than 10 employees.

Group employees by department, count each group, then keep only the groups above 10 with HAVING COUNT(*) > 10, because HAVING judges finished groups while WHERE would judge individual employees before grouping. The same grouped numbers often feed charts in Tableau.

Subqueries

Correlated vs non-correlated subquery?

A non-correlated subquery runs once; a correlated one references the outer query and runs per row, so it can be slower.

Logic

How do you use CASE WHEN?

To create conditional columns, such as bucketing customers into High, Medium and Low spenders, or for conditional aggregation.

Sets

UNION vs UNION ALL?

Stacking January and February sales tables? UNION ALL simply appends them, while UNION also hunts for matching rows, which costs time and can silently drop two genuinely identical orders, so default to UNION ALL. It works like combining DataFrames in Python.

Knowing answers is half the job; writing queries under time pressure is the other half. Practise with a trainer.

Book a free demo

Advanced questions

Advanced SQL and window function questions

Window functions are the single biggest differentiator in analyst SQL rounds.

Window

What is a window function?

With GROUP BY you get one row per department; with a window function you keep every employee row and simply add one more column showing that department’s average beside it, as explained in the PostgreSQL documentation.

Window

How do you calculate a running total?

To add up sales day by day, SUM(amount) OVER (ORDER BY order_date) makes day 3 show days 1 to 3 combined, and adding PARTITION BY customer_id restarts that count for every customer. Both MySQL and PostgreSQL support this syntax.

Window

What do LAG and LEAD do?

LAG lets each row peek at the row above it, so this month’s revenue sits next to last month’s and growth is one subtraction away; LEAD does the same by peeking at the row below. Our trainers teach both with live examples, as you can see on the About page.

Performance

How would you speed up a slow query?

Check the execution plan, add indexes on join and filter columns, avoid SELECT *, filter early and replace repeated subqueries with CTEs or joins.

Query practice

Queries you may be asked to write live

Know the pattern for each of these and you can handle most live rounds.

Task

Pattern to use

Top 3 products by revenue in each category

DENSE_RANK() OVER (PARTITION BY category ORDER BY revenue DESC), then filter rank ≤ 3

Customers who never placed an order

LEFT JOIN orders and filter where the order id IS NULL (or NOT EXISTS)

Month-over-month revenue growth

Aggregate by month in a CTE, then LAG(revenue) to compare with the previous month

Delete duplicate rows but keep one

ROW_NUMBER() OVER (PARTITION BY duplicate columns), keep row_number = 1

Employees earning more than their manager

Self join employees e to employees m on e.manager_id = m.id where e.salary > m.salary

💡 Practise each pattern on a sample database such as AdventureWorks. Our SQL course in Hyderabad drills these daily.

Live round tips

How to handle a live SQL round

Interviewers care as much about how you think as about the final query.

01

Clarify the question

Before typing SELECT, ask three things out loud: what one row in each table represents, whether duplicates are possible, and how ties should be handled. More preparation guides are on our blog.

02

Think out loud

Explain your plan: which tables to join, how to group and how to filter.

03

Build step by step

Start simple, check the output, then add joins, grouping or window functions.

04

Test edge cases

Mention how your query handles NULLs, ties and empty results.

✕ Jumping straight into code without understanding the tables.

✕ Using SELECT * and GROUP BY on columns you don't need.

✕ Staying silent when stuck. Talk through your approach; partial credit is real.

FAQs

SQL interview questions, answered

Which SQL database should I practise on?

MySQL, PostgreSQL or SQL Server are all fine. Core syntax is very similar; companies care that you know the concepts.

Are window functions asked in fresher interviews?

Increasingly, yes. ROW_NUMBER, RANK and running totals now appear even in fresher rounds at many companies.

How many SQL problems should I practise?

Aim for 50–100 varied problems covering joins, grouping, subqueries and window functions, rather than repeating easy ones.

Is SQL enough to get a data analyst job?

SQL gets you the data, but analyst job posts usually also list Excel and a dashboard tool, so plan to pair your SQL practice with one reporting project, which is how our data analytics course in Hyderabad is structured.

How long does it take to learn SQL for interviews?

If you can practice one hour daily, spend week 1 on filtering and aggregates, weeks 2 and 3 on JOINs and subqueries, and weeks 4 to 6 on window functions plus timed mock questions. Want a personal plan? Contact us.

Do you offer a standalone SQL course?

Yes. Our 30-day SQL course costs ₹25,000 classroom or ₹20,000 online. SQL is also part of the full data analytics program.

✍️

Written by the Data Analytics Masters training team

Our SQL trainer has prepared many batches of analysts for interviews in Hyderabad. These questions reflect what students report from real technical rounds.

Ready to start?

Make SQL your strongest interview round

Learn SQL in depth in our data analytics course in Hyderabad, or take the focused 30-day SQL course.

Keep reading

🎓 Free demo class

Book Your Free Demo

Share your details and our team will call you to schedule a free data analytics demo class.

✅ Thank you! Our team will contact you shortly.

🔒 Your details are safe with us. No spam.