Interview Q&A · questions with model answers
SQL & Databases Interview Questions
Part of the study plan for: Backend Engineer · Full Stack Engineer · Data Engineer
Ordered by how often they're asked. Most-asked answers are free to read in full; members see every answer and can rate their confidence on each.
-
Most asked SQL interview: explain INNER JOIN.
Returns matching rows from both tables on join predicate.
-
Most asked SQL interview: explain LEFT JOIN.
All left rows plus matches; NULLs when no match.
-
Most asked SQL interview: explain GROUP BY.
Aggregate per group; SELECT non-aggregates must be grouped.
-
Most asked SQL interview: explain HAVING.
Filter groups after aggregation.
-
Most asked SQL interview: explain window functions.
ROW_NUMBER/RANK/SUM OVER partitions without collapsing rows.
-
Most asked SQL interview: explain ACID.
Atomicity, Consistency, Isolation, Durability.
-
Most asked SQL interview: explain isolation levels.
Read uncommitted to serializable; trade consistency vs concurrency.
-
Most asked Data modeling: normalization 1NF/2NF/3NF?
Reduce redundancy and update anomalies; 3NF common target.
-
Most asked Indexing/performance: B-tree index?
Default for equality/range queries on ordered keys.
-
Most asked Indexing/performance: EXPLAIN / EXPLAIN ANALYZE?
Inspect planned vs actual query execution.
-
SQL interview: explain SELECT filtering.
WHERE filters rows before grouping; use AND/OR carefully with parentheses.
-
SQL interview: explain NULL semantics.
NULL means unknown; use IS NULL; aggregates ignore NULLs.
-
SQL interview: explain transactions.
BEGIN/COMMIT/ROLLBACK; ACID properties.
-
Data modeling: primary key?
Unique identifier for rows; often surrogate integer/UUID.
-
Data modeling: foreign key?
Referential integrity to another table's key.
-
Data modeling: many-to-many?
Resolved via junction/bridge table.
-
Indexing/performance: composite index?
Leftmost prefix rule matters for multi-column indexes.
-
Indexing/performance: index write overhead?
Indexes speed reads but slow writes and use space.
-
SQL interview: explain RIGHT / FULL JOIN.
Right keeps right side; FULL keeps both with NULLs for non-matches.
-
SQL interview: explain ORDER BY / LIMIT.
Sort and truncate result sets; note OFFSET costs.
-
SQL interview: explain subqueries.
Nested SELECT in WHERE/FROM/SELECT; correlated vs non-correlated.
-
SQL interview: explain CTEs (WITH).
Named subqueries improving readability; materialization varies by engine.
-
SQL interview: explain CASE expressions.
Conditional logic in SQL projections/aggregations.
-
SQL interview: explain dirty/nonrepeatable/phantom reads.
Anomalies prevented by higher isolation.
-
Data modeling: denormalization?
Intentional redundancy for read performance.
-
Data modeling: constraints?
UNIQUE, CHECK, NOT NULL enforce integrity in DB.
-
Indexing/performance: covering index?
Index includes all columns needed so heap fetch avoided.
-
Indexing/performance: cardinality?
Distinct value counts influence plans.
-
Indexing/performance: vacuum / analyze (Postgres)?
Reclaim dead tuples and refresh statistics.
-
SQL interview: explain CROSS JOIN.
Cartesian product; rarely intentional without filters.
-
SQL interview: explain DISTINCT.
Deduplicate rows; can be expensive—ensure need.
-
Data modeling: star schema?
Fact table + dimensions for analytics.
-
Data modeling: 1:1 relationships?
Separate table for optional/heavy attributes or security.
-
Indexing/performance: hash index?
Equality only (engine-specific caveats).
-
Indexing/performance: partial index?
Index subset of rows matching predicate.