Interview Q&A · 42 questions · 10 answered publicly

SQL & Databases Interview Questions

Ordered by how often they're asked. Sign in free to see every answer, rate your confidence and run timed mock interviews.

  1. Most asked SQL interview: explain INNER JOIN.

    Summary

    Returns matching rows from both tables on join predicate.

    Longer Answer

    Returns matching rows from both tables on join predicate. SQL topic: INNER JOIN.

    Key Points

    • Returns matching rows from both tables on join predicate
    • SQL topic: INNER JOIN
    • Relevant areas: SQL, Query
    • Use the answer to connect the concept back to a realistic production or interview scenario for 'SQL interview: explain INNER JOIN.'

    Comparison / Tradeoffs

    Aspect Notes
    Core idea Returns matching rows from both tables on join predicate.
    Practical tradeoff SQL topic: INNER JOIN.

    Permalink

  2. Most asked SQL interview: explain LEFT JOIN.

    Summary

    All left rows plus matches; NULLs when no match.

    Longer Answer

    All left rows plus matches; NULLs when no match. SQL topic: LEFT JOIN.

    Key Points

    • All left rows plus matches; NULLs when no match
    • SQL topic: LEFT JOIN
    • Relevant areas: SQL, Query
    • Use the answer to connect the concept back to a realistic production or interview scenario for 'SQL interview: explain LEFT JOIN.'

    Comparison / Tradeoffs

    Aspect Notes
    Core idea All left rows plus matches; NULLs when no match.
    Practical tradeoff SQL topic: LEFT JOIN.

    Permalink

  3. Most asked SQL interview: explain GROUP BY.

    Summary

    Aggregate per group; SELECT non-aggregates must be grouped.

    Longer Answer

    Aggregate per group; SELECT non-aggregates must be grouped. SQL topic: GROUP BY.

    Key Points

    • Aggregate per group; SELECT non-aggregates must be grouped
    • SQL topic: GROUP BY
    • Relevant areas: SQL, Query
    • Use the answer to connect the concept back to a realistic production or interview scenario for 'SQL interview: explain GROUP BY.'

    Comparison / Tradeoffs

    Aspect Notes
    Core idea Aggregate per group; SELECT non-aggregates must be grouped.
    Practical tradeoff SQL topic: GROUP BY.

    Permalink

  4. Most asked SQL interview: explain HAVING.

    Summary

    Filter groups after aggregation.

    Longer Answer

    Filter groups after aggregation. SQL topic: HAVING.

    Key Points

    • Filter groups after aggregation
    • SQL topic: HAVING
    • Relevant areas: SQL, Query
    • Use the answer to connect the concept back to a realistic production or interview scenario for 'SQL interview: explain HAVING.'

    Comparison / Tradeoffs

    Aspect Notes
    Core idea Filter groups after aggregation.
    Practical tradeoff SQL topic: HAVING.

    Permalink

  5. Most asked SQL interview: explain window functions.

    Summary

    ROW_NUMBER/RANK/SUM OVER partitions without collapsing rows.

    Longer Answer

    ROW_NUMBER/RANK/SUM OVER partitions without collapsing rows. SQL topic: window functions.

    Key Points

    • ROW_NUMBER/RANK/SUM OVER partitions without collapsing rows
    • SQL topic: window functions
    • Relevant areas: SQL, Query
    • Use the answer to connect the concept back to a realistic production or interview scenario for 'SQL interview: explain window functions.'

    Comparison / Tradeoffs

    Aspect Notes
    Core idea ROW_NUMBER/RANK/SUM OVER partitions without collapsing rows.
    Practical tradeoff SQL topic: window functions.

    Permalink

  6. Most asked SQL interview: explain ACID.

    Summary

    Atomicity, Consistency, Isolation, Durability.

    Longer Answer

    Atomicity, Consistency, Isolation, Durability. SQL topic: ACID.

    Key Points

    • Atomicity, Consistency, Isolation, Durability
    • SQL topic: ACID
    • Relevant areas: SQL, Query
    • Use the answer to connect the concept back to a realistic production or interview scenario for 'SQL interview: explain ACID.'

    Comparison / Tradeoffs

    Aspect Notes
    Core idea Atomicity, Consistency, Isolation, Durability.
    Practical tradeoff SQL topic: ACID.

    Permalink

  7. Most asked SQL interview: explain isolation levels.

    Summary

    Read uncommitted to serializable; trade consistency vs concurrency.

    Longer Answer

    Read uncommitted to serializable; trade consistency vs concurrency. SQL topic: isolation levels.

    Key Points

    • Read uncommitted to serializable; trade consistency vs concurrency
    • SQL topic: isolation levels
    • Relevant areas: SQL, Query
    • Use the answer to connect the concept back to a realistic production or interview scenario for 'SQL interview: explain isolation levels.'

    Comparison / Tradeoffs

    Aspect Notes
    Core idea Read uncommitted to serializable; trade consistency vs concurrency.
    Practical tradeoff Read uncommitted to serializable; trade consistency vs concurrency.

    Permalink

  8. Most asked Data modeling: normalization 1NF/2NF/3NF?

    Summary

    Reduce redundancy and update anomalies; 3NF common target.

    Longer Answer

    Reduce redundancy and update anomalies; 3NF common target. Modeling: normalization 1NF/2NF/3NF.

    Key Points

    • Reduce redundancy and update anomalies; 3NF common target
    • Modeling: normalization 1NF/2NF/3NF
    • Relevant areas: SQL, Modeling
    • Use the answer to connect the concept back to a realistic production or interview scenario for 'Data modeling: normalization 1NF/2NF/3NF?'

    Comparison / Tradeoffs

    Aspect Notes
    Core idea Reduce redundancy and update anomalies; 3NF common target.
    Practical tradeoff Modeling: normalization 1NF/2NF/3NF.

    Permalink

  9. Most asked Indexing/performance: B-tree index?

    Summary

    Default for equality/range queries on ordered keys.

    Longer Answer

    Default for equality/range queries on ordered keys. Perf: B-tree index.

    Key Points

    • Default for equality/range queries on ordered keys
    • Perf: B-tree index
    • Relevant areas: SQL, Performance
    • Use the answer to connect the concept back to a realistic production or interview scenario for 'Indexing/performance: B-tree index?'

    Comparison / Tradeoffs

    Aspect Notes
    Core idea Default for equality/range queries on ordered keys.
    Practical tradeoff Perf: B-tree index.

    Permalink

  10. Most asked Indexing/performance: EXPLAIN / EXPLAIN ANALYZE?

    Summary

    Inspect planned vs actual query execution.

    Longer Answer

    Inspect planned vs actual query execution. Perf: EXPLAIN / EXPLAIN ANALYZE.

    Key Points

    • Inspect planned vs actual query execution
    • Perf: EXPLAIN / EXPLAIN ANALYZE
    • Relevant areas: SQL, Performance
    • Use the answer to connect the concept back to a realistic production or interview scenario for 'Indexing/performance: EXPLAIN / EXPLAIN ANALYZE?'

    Comparison / Tradeoffs

    Aspect Notes
    Core idea Inspect planned vs actual query execution.
    Practical tradeoff Inspect planned vs actual query execution.

    Permalink

  11. SQL interview: explain SELECT filtering.
  12. SQL interview: explain NULL semantics.
  13. SQL interview: explain transactions.
  14. Data modeling: primary key?
  15. Data modeling: foreign key?
  16. Data modeling: many-to-many?
  17. Indexing/performance: composite index?
  18. Indexing/performance: index write overhead?
  19. SQL interview: explain RIGHT / FULL JOIN.
  20. SQL interview: explain ORDER BY / LIMIT.
  21. SQL interview: explain subqueries.
  22. SQL interview: explain CTEs (WITH).
  23. SQL interview: explain UNION vs UNION ALL.
  24. SQL interview: explain EXISTS vs IN.
  25. SQL interview: explain CASE expressions.
  26. SQL interview: explain dirty/nonrepeatable/phantom reads.
  27. Data modeling: denormalization?
  28. Data modeling: surrogate vs natural keys?
  29. Data modeling: OLTP vs OLAP?
  30. Data modeling: constraints?
  31. Indexing/performance: covering index?
  32. Indexing/performance: sequential vs index scan?
  33. Indexing/performance: cardinality?
  34. Indexing/performance: vacuum / analyze (Postgres)?
  35. SQL interview: explain CROSS JOIN.
  36. SQL interview: explain DISTINCT.
  37. Data modeling: star schema?
  38. Data modeling: 1:1 relationships?
  39. Indexing/performance: hash index?
  40. Indexing/performance: partial index?
  41. What are the different types of JOINs in SQL?
  42. Why are indexes important in a database?