HomeInterview QuestionsSQL Interview QuestionsTop 10
🗄️
Free Study Guide · 2025

Top 10 SQLInterview Questions & Answers (2025)

SQL is tested in every backend, data engineering, data analyst, and SDE interview. Whether you're joining TCS as a fresher or interviewing for a data role at Flipkart or Swiggy, these are the queries and concepts you will be asked.

10 questions
Detailed answers
100% free
Also available:Top 20All 20 questions →
1What is the difference between INNER JOIN, LEFT JOIN, RIGHT JOIN, and FULL OUTER JOIN?
INNER JOIN returns rows that have matching values in both tables. LEFT JOIN returns all rows from the left table and matched rows from the right (NULL for no match). RIGHT JOIN is the mirror — all rows from the right. FULL OUTER JOIN returns all rows from both, with NULLs where there's no match. LEFT JOIN is the most commonly used; INNER JOIN is the default.
2What is the difference between WHERE and HAVING?
WHERE filters rows before grouping (before GROUP BY is applied) and cannot use aggregate functions. HAVING filters groups after GROUP BY and can use aggregate functions (HAVING COUNT(*) > 5). Rule of thumb: WHERE filters individual rows; HAVING filters aggregated groups. You can use both in the same query.
3What are indexes and how do they improve query performance?
An index is a data structure (typically a B-tree) that allows the database to find rows without scanning the entire table. Like a book index, it maps column values to row locations. Indexes dramatically speed up SELECT queries with WHERE, JOIN, and ORDER BY on indexed columns but slow down INSERT/UPDATE/DELETE (the index must be maintained). Create indexes on columns used in WHERE and JOIN conditions.
4What is database normalisation? Explain 1NF, 2NF, 3NF.
Normalisation reduces data redundancy and improves integrity. 1NF: each column has atomic (indivisible) values, no repeating groups. 2NF: 1NF + every non-key attribute is fully functionally dependent on the entire primary key (no partial dependency — matters for composite keys). 3NF: 2NF + no transitive dependencies (non-key attribute doesn't depend on another non-key attribute).
5What is a PRIMARY KEY vs UNIQUE KEY?
A PRIMARY KEY uniquely identifies each row, cannot be NULL, and there can only be one per table. A UNIQUE KEY also enforces uniqueness but allows one NULL and there can be multiple per table. Both create an index automatically. Use PRIMARY KEY for the entity identifier; use UNIQUE constraints for other columns that must be unique (email, username).
6What is a transaction? What are ACID properties?
A transaction is a sequence of operations executed as a single unit. ACID properties ensure reliability: Atomicity (all operations succeed or all are rolled back), Consistency (the database moves from one valid state to another), Isolation (concurrent transactions appear sequential), Durability (committed data survives system failures). Transactions are critical for financial operations.
7What is the difference between DELETE, TRUNCATE, and DROP?
DELETE removes specific rows based on a WHERE clause — it's DML, logged, and can be rolled back. TRUNCATE removes all rows from a table instantly — it's DDL, minimally logged, cannot be used with WHERE, and in many databases cannot be rolled back within a transaction. DROP removes the entire table structure and data permanently.
8What are window functions in SQL?
Window functions perform calculations across a set of rows related to the current row (a 'window') without collapsing them into groups like GROUP BY. Common functions: ROW_NUMBER(), RANK(), DENSE_RANK() for ranking; LAG(), LEAD() for accessing previous/next rows; SUM(), AVG() with OVER (PARTITION BY col ORDER BY col). Essential for analytics queries.
9What is a subquery vs a CTE?
A subquery is a query nested inside another query (in WHERE, FROM, or SELECT clause). A CTE (Common Table Expression) uses the WITH keyword to define a named, temporary result set you can reference multiple times in the main query. CTEs are more readable for complex queries, can be recursive, and some databases optimise them as materialised results.
10What is the difference between UNION and UNION ALL?
UNION combines result sets of two queries and removes duplicate rows (requires sorting/hashing). UNION ALL combines result sets and keeps all duplicates — it's faster because no deduplication is needed. Use UNION when duplicates are a concern; use UNION ALL for performance when you know results are distinct or duplicates are acceptable.
See all 20 SQL questions →
Level up your prep
Get company-specific SQL questions
Upload your resume → get questions tailored to Google, Amazon, TCS, and 50+ companies.
Try AI Interview Prep →
© 2025 CareerLens · Home · Interview Questions · Pricing