SQL Interview Questions
MCQ Quiz · All Difficulty Levels
Practice SQL interview questions with MCQs covering every query concept tested in technical interviews for data engineering, backend engineering, and analyst roles. Topics include SELECT statements and filtering, all JOIN types (INNER, LEFT, RIGHT, FULL OUTER, SELF, CROSS), GROUP BY and aggregate functions, subqueries and correlated subqueries, CTEs (Common Table Expressions), window functions (ROW_NUMBER, RANK, DENSE_RANK, LAG, LEAD, SUM OVER), indexes and query optimization fundamentals, transactions and ACID properties, database normalization (1NF, 2NF, 3NF, BCNF), stored procedures and views, and NULL handling. SQL is tested at companies of every type, data-focused startups, SaaS product companies, financial institutions, and large tech firms, often as a hands-on coding round with real schema design. Four difficulty levels progress from Trainee (basic SELECT, filtering, simple JOINs) through Junior Dev (multiple JOINs, GROUP BY, subqueries) and Mid Level (CTEs, window functions, query plans, indexes) to Senior Dev (indexing strategy, transactions, normalization trade-offs, performance). Practice regularly to build the SQL fluency that interview rounds demand.
Frequently Asked Questions: SQL Interviews
Common questions developers ask when preparing for SQL technical interviews.
What SQL topics are most commonly tested in data and backend interviews?
JOINs are almost always tested, interviewers want to see you write INNER, LEFT, and multi-table JOINs correctly. GROUP BY with aggregates, subqueries, and CTEs follow closely. Window functions (ROW_NUMBER, RANK, LAG, LEAD) are increasingly tested for analytics and data engineering roles. Query optimization (indexes, explain plans) and transaction concepts (ACID properties) come up in backend and senior data roles.
What is the difference between INNER JOIN and LEFT JOIN in SQL?
INNER JOIN returns only rows that have matching values in both tables, rows without a match in either table are excluded. LEFT JOIN (also called LEFT OUTER JOIN) returns all rows from the left table and matched rows from the right table; where there is no match, the right-table columns contain NULL. LEFT JOIN is used when you want to keep all records from the primary table regardless of whether related data exists in the second table.
What are window functions and when would you use them in SQL?
Window functions perform calculations across a set of rows related to the current row, unlike GROUP BY, they do not collapse rows into groups. Common window functions include ROW_NUMBER (unique sequential number per partition), RANK and DENSE_RANK (rankings with tie handling), LAG and LEAD (access previous/next row values), and SUM/AVG OVER (running totals and moving averages). They are essential for ranking queries, time-series analysis, and comparing rows within groups.
What is a CTE in SQL and how is it different from a subquery?
A Common Table Expression (CTE), defined with the WITH keyword, is a named temporary result set you can reference in the main query. Unlike a subquery, a CTE is defined once and can be referenced multiple times, making complex queries more readable and maintainable. Recursive CTEs can query hierarchical data (org charts, bill of materials). Most modern databases optimize CTEs similarly to subqueries, though there are database-specific differences in materialization.
How should I prepare for a SQL coding round in a technical interview?
Practice writing queries by hand against real schemas, do not rely on visual query builders. Focus on JOINs across three or more tables, GROUP BY with HAVING clauses, and at least two window function patterns. Study how to read a schema diagram quickly and identify which tables to JOIN. Review NULL handling, since many bugs in interview queries come from forgetting that aggregate functions ignore NULLs and that NULL comparisons require IS NULL rather than = NULL.