SQL Interview Questions for Data Analytics: Complete Guide 2026

March 23, 2026
📄 Free PDF Download

SQL Interview Questions for Data Analysts 2026

Master SQL for your next data analyst interview — covering JOINs, window functions, subqueries, aggregate functions, and real query challenges asked at top companies.

✓ 50 SQL Questions✓ With Query Examples✓ Free PDF✓ Updated 2026
🔒 Get the Free SQL Interview PDF
50 SQL questions with query examples and model answers — free instant download.
✅ Done! Your SQL PDF is ready.
Click below for instant access to your free SQL interview questions PDF.
📥 Download PDF Now
Chat on WhatsApp

SQL Interview Questions for Data Analysts: Why SQL is the #1 Skill in 2026

These SQL interview questions for data analysts cover the full range of topics you will encounter in technical screenings — from basic queries to advanced window functions and performance optimisation. SQL (Structured Query Language) is the bedrock of data analytics. Despite the rise of Python, R, and BI tools, SQL remains the most requested skill in data analyst job descriptions — appearing in over 85% of analyst roles across India. Whether you are querying a MySQL database, exploring a Snowflake warehouse, or building reports in Power BI, SQL is the language that connects you to data.

In interviews, SQL is tested through live coding exercises, case study queries, and conceptual questions. This guide covers the most frequently asked SQL interview questions for data analyst roles in 2026, with real query examples and detailed explanations.

Section 1 — SQL Fundamentals

Q1. What is the difference between WHERE and HAVING?

WHERE filters rows before any aggregation is applied — it cannot be used with aggregate functions. HAVING filters groups after GROUP BY aggregation. Use WHERE to filter individual rows; use HAVING to filter aggregated results. Example: to find departments with more than 10 employees earning over ₹50,000, combine both — WHERE salary > 50000 filters rows first, then HAVING COUNT(*) > 10 filters the grouped result.

Q2. Explain all types of SQL JOINs with examples.

INNER JOIN: Returns matching rows from both tables only. LEFT JOIN: All rows from left table + matches from right (NULLs where no match). RIGHT JOIN: All rows from right + matches from left. FULL OUTER JOIN: All rows from both tables with NULLs where no match. CROSS JOIN: Cartesian product of both tables. SELF JOIN: Table joined to itself, useful for hierarchical data like employee-manager relationships.

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

UNION combines results from two SELECT queries and removes duplicate rows — it applies a DISTINCT operation internally, making it slower. UNION ALL combines results and keeps all duplicates — it is faster and preferred when you know there are no duplicates or when duplicates are intentional. Both queries must have the same number of columns with compatible data types.

Q4. What are aggregate functions in SQL?

Aggregate functions compute a single result from a set of values: COUNT() counts rows, SUM() totals numeric values, AVG() calculates the average, MAX() and MIN() find extremes, GROUP_CONCAT() (MySQL) concatenates values. They are used with GROUP BY to calculate metrics per category. COUNT(*) counts all rows including NULLs; COUNT(column) skips NULL values.

Q5. What is a subquery and when should you use it?

A subquery is a SELECT statement nested inside another query. It can appear in WHERE, FROM, or SELECT clauses. Use subqueries when you need to filter using an aggregated value (e.g., find employees earning above the average salary) or when breaking a complex query into logical steps. For performance-critical queries, CTEs (WITH clauses) are often more readable and optimised by modern query planners.

Section 2 — Intermediate SQL Questions

Q6. Write a SQL query to find the second highest salary.

Method 1 using subquery: SELECT MAX(salary) FROM employees WHERE salary < (SELECT MAX(salary) FROM employees). Method 2 using LIMIT/OFFSET: SELECT DISTINCT salary FROM employees ORDER BY salary DESC LIMIT 1 OFFSET 1. Method 3 using window functions: SELECT salary FROM (SELECT salary, DENSE_RANK() OVER (ORDER BY salary DESC) AS rnk FROM employees) t WHERE rnk = 2. The window function approach is most robust for Nth highest salary.

Q7. What are window functions and how do they differ from GROUP BY?

Window functions (OVER clause) perform calculations across a partition of rows related to the current row without collapsing rows into a single output. GROUP BY aggregates rows into one result per group. Window functions retain each row while also computing aggregates, rankings, or offsets. Common functions: ROW_NUMBER() (unique sequential rank), RANK() (ties get same rank with gaps), DENSE_RANK() (ties with no gaps), LAG() and LEAD() (access previous/next row values), SUM() OVER() and AVG() OVER() (running totals).

Q8. What is a CTE (Common Table Expression)?

A CTE is a temporary named result set defined with the WITH keyword before a SELECT statement. It improves query readability by breaking complex logic into labelled steps. CTEs can be referenced multiple times in the same query and support recursion (recursive CTEs) for hierarchical data like organisational charts. Unlike subqueries, CTEs are defined once at the top, making the main query cleaner and easier to debug.

Q9. Explain the difference between DELETE, TRUNCATE, and DROP.

DELETE removes specific rows based on a WHERE condition, logs each deletion, and can be rolled back within a transaction. TRUNCATE removes all rows from a table instantly without logging individual deletions — faster but cannot be rolled back in most databases. DROP removes the entire table structure, all data, and all associated constraints and indexes permanently. DROP cannot be rolled back and requires recreating the table from scratch.

Q10. What is indexing in SQL and why does it matter for performance?

An index is a data structure that speeds up data retrieval by allowing the database engine to find rows without scanning the entire table. Primary keys are automatically indexed. Analysts should add indexes on frequently filtered columns (WHERE), joined columns, and ORDER BY columns. Over-indexing slows down INSERT/UPDATE/DELETE operations. A clustered index determines the physical order of data; a non-clustered index is a separate lookup structure pointing to data rows.

Section 3 — Advanced SQL for Data Analysts

Q11. Write a query to calculate a 7-day rolling average of daily sales.

Use AVG() as a window function with a ROWS BETWEEN frame: SELECT date, daily_sales, AVG(daily_sales) OVER (ORDER BY date ROWS BETWEEN 6 PRECEDING AND CURRENT ROW) AS rolling_7_day_avg FROM sales_table ORDER BY date. The ROWS BETWEEN clause defines a moving window of the current row plus the 6 rows before it, computing the average across that 7-day window for each row in the result set.

Q12. How do you identify and remove duplicate rows in SQL?

To identify duplicates: SELECT column1, column2, COUNT(*) FROM table GROUP BY column1, column2 HAVING COUNT(*) > 1. To delete duplicates while keeping one row, use ROW_NUMBER(): DELETE FROM table WHERE id IN (SELECT id FROM (SELECT id, ROW_NUMBER() OVER (PARTITION BY col1, col2 ORDER BY id) AS rn FROM table) t WHERE rn > 1). Always backup data before bulk deletes.

Q13. What is normalisation in database design?

Normalisation is the process of organising database tables to reduce redundancy and improve data integrity through a series of normal forms. 1NF: Eliminate repeating groups; each column has atomic values. 2NF: Remove partial dependencies (every non-key column depends on the full primary key). 3NF: Remove transitive dependencies (non-key columns depend only on primary key, not on other non-key columns). Analysts mostly work with already-normalised schemas but understanding them helps in query optimisation.

Q14. What is the difference between a view and a materialised view?

A view is a virtual table defined by a stored SQL query — it does not store data itself, so it always reflects current data but recomputes on every query. A materialised view stores the result of the query on disk and refreshes at defined intervals. Materialised views are much faster for complex aggregation queries on large datasets but may show slightly stale data. They are commonly used in data warehouses like Snowflake and Redshift.

Q15. Write a SQL query to find customers who placed orders in every month of 2024.

Use COUNT(DISTINCT month) with HAVING: SELECT customer_id FROM orders WHERE YEAR(order_date) = 2024 GROUP BY customer_id HAVING COUNT(DISTINCT MONTH(order_date)) = 12. This groups orders by customer, extracts the month from the order date, counts distinct months, and returns only those customers who appear in all 12 months. Adjust the date function syntax for your specific database (MONTH() for MySQL, EXTRACT(MONTH FROM date) for PostgreSQL).
Pro Tip: Practice writing queries from scratch without an IDE. Interviewers at FAANG and top consulting firms often ask you to write SQL on a whiteboard or in a plain text editor.

Related Free Resources

Frequently Asked Questions

What SQL topics are most tested in data analyst interviews?
The most tested topics are JOINs (especially LEFT and INNER), GROUP BY with HAVING, subqueries, window functions (ROW_NUMBER, RANK, LAG), CTEs, and query optimisation concepts like indexing.
Is SQL still relevant for data analysts in 2026?
Absolutely. SQL appears in over 85% of data analyst job descriptions and is the primary language for querying databases, data warehouses, and BI tools. Python is complementary, not a replacement.
What is the difference between DELETE, TRUNCATE, and DROP?
DELETE removes specific rows and can be rolled back. TRUNCATE removes all rows instantly without logging and is faster but usually cannot be rolled back. DROP removes the entire table and its structure permanently.
What are SQL window functions?
Window functions compute values across a set of rows related to the current row using OVER(). Unlike GROUP BY, they do not collapse rows. Key functions: ROW_NUMBER, RANK, DENSE_RANK, LAG, LEAD, SUM OVER, AVG OVER.
How do I get the SQL Interview Questions PDF?
Fill in your name and email in the download form above. You will get instant free access to the complete SQL for Data Analysts interview questions PDF.

Ready to Land a Data Analyst Role?

Join GROWAI EdTech's Data Analytics course — master SQL, Python, Excel & Power BI with live mentorship and guaranteed placement support.

×

🆕 Wait — Get the Free SQL PDF

50 SQL interview questions with query examples for data analysts. Free download, no spam.

No thanks

Leave a Comment