Interview Prep | SQL
SQL Interview Questions

Entry, Mid, and Advanced SQL questions with short answers. Use search to filter questions quickly.

🔍

SQL Entry Level Q&A

Back to Top ↑
🗃️
Q1. What is a primary key?
A. A column (or columns) that uniquely identifies each row in a table.
Entry
🗃️
Q2. WHERE vs ORDER BY?
A. WHERE filters rows; ORDER BY sorts the result.
Entry
🗃️
Q3. What does GROUP BY do?
A. It groups rows so you can use aggregates like COUNT, SUM, AVG.
Entry
🗃️
Q4. INNER JOIN vs LEFT JOIN?
A. INNER returns only matches; LEFT returns all rows from left and matches from right (NULL if none).
Entry
🗃️
Q5. What is NULL?
A. Represents unknown/missing value. Use IS NULL / IS NOT NULL for checks.
Entry
🗃️
Q6. What is DISTINCT?
A. It removes duplicate rows in the result set.
Entry
🗃️
Q7. What is an index?
A. A structure to speed up lookups/sorts at the cost of storage and slower writes.
Entry
🗃️
Q8. What is a foreign key?
A. A constraint linking rows between tables to enforce referential integrity.
Entry

SQL Mid Level Q&A

Back to Top ↑
⚙️
Q1. WHERE vs HAVING?
A. WHERE filters rows before grouping; HAVING filters groups after GROUP BY.
Mid
⚙️
Q2. What is normalization?
A. Design rules to reduce redundancy and improve integrity (1NF/2NF/3NF).
Mid
⚙️
Q3. What is a transaction?
A. A unit of work that commits or rolls back as a whole.
Mid
⚙️
Q4. What is ACID?
A. Atomicity, Consistency, Isolation, Durability.
Mid
⚙️
Q5. What is a correlated subquery?
A. A subquery that references the outer query and can run per outer row.
Mid
⚙️
Q6. What is EXPLAIN used for?
A. To view the query plan and understand index usage and join strategies.
Mid
⚙️
Q7. What is an upsert?
A. Insert if not exists; otherwise update (syntax depends on DB).
Mid
⚙️
Q8. What is a composite index?
A. An index on multiple columns; order matters for which queries it can help.
Mid

SQL Advanced Level Q&A

Back to Top ↑
🚀
Q1. What are window functions?
A. Functions like ROW_NUMBER() OVER(...) that compute across a window without collapsing rows.
Advanced
🚀
Q2. How do isolation levels affect anomalies?
A. They control dirty/non-repeatable/phantom reads; stronger isolation reduces anomalies with more locking/overhead.
Advanced
🚀
Q3. What is a covering index?
A. An index that contains all columns needed by a query, avoiding table lookups.
Advanced
🚀
Q4. Clustered vs non-clustered index?
A. Clustered affects physical row order (engine-dependent). Non-clustered stores keys + pointers.
Advanced
🚀
Q5. When is an index not used?
A. Low selectivity, function on indexed column, leading wildcard LIKE "%x", or optimizer choice.
Advanced
🚀
Q6. What is cardinality?
A. Estimated number of rows; impacts plan selection. Bad stats can cause slow plans.
Advanced
🚀
Q7. What is partitioning?
A. Splitting a table into parts (range/hash/list) to improve manageability and performance.
Advanced
🚀
Q8. How do you prevent deadlocks?
A. Keep transactions short, access rows in consistent order, use proper indexes, and retry on deadlock.
Advanced