Queries that survive scale
SQL Interview Questions
Joins, window functions, indexes, transactions and query plans. Learn to reason about data, not memorise syntax.
40 questions10 easy22 medium8 hard0/40 learned
01What is SQL and what is it used for?Easysql · relational databases · querying02How do you choose between SQL and NoSQL databases?Mediumsql · nosql · data modelling03How does a SELECT statement execute?Easyselect · query semantics · clauses04What is the difference between WHERE and HAVING?Mediumwhere · having · aggregation05How do joins work in SQL?Easyjoins · relationships · querying06What is the difference between INNER JOIN and LEFT JOIN?Mediuminner join · left join · nulls07What is a self-join and when do you use one?Mediumself join · hierarchies · aliases08What is the difference between UNION and UNION ALL?Mediumunion · set operations · performance09How does GROUP BY work?Easygroup by · aggregation · query semantics10How do COUNT, SUM, AVG, MIN, and MAX behave?Easyaggregates · count · nulls11What are window functions and when should you use them?Mediumwindow functions · analytics · partitioning12What is the difference between RANK, DENSE_RANK, and ROW_NUMBER?Mediumranking · window functions · ties13What is a CTE and why would you use one?Mediumcte · readability · with clause14How does a recursive CTE work?Hardrecursive cte · hierarchies · graphs15What are subqueries and where can they appear?Mediumsubqueries · scalar · derived tables16What is a correlated subquery and how does it perform?Hardcorrelated subqueries · performance · query plans17When should you use EXISTS instead of IN?Mediumexists · in · nulls18How does the CASE expression work?Easycase · conditional logic · aggregation19How does SQL handle NULL values?Mediumnulls · three-valued logic · coalesce20What is the difference between a primary key and a foreign key?Easyprimary key · foreign key · constraints21How do UNIQUE constraints work and what are the edge cases?Mediumunique constraints · indexes · nulls22What is an index and what does it cost?Mediumindexes · btree · performance23How do composite indexes and the leftmost prefix rule work?Mediumcomposite indexes · column order · query planning24What is index selectivity and why does it matter?Hardselectivity · statistics · indexes25How do you read a query execution plan?Hardquery plans · explain · optimizer26What is database normalization and why does it matter?Mediumnormalization · schema design · constraints27When and how would you denormalize a schema?Mediumdenormalization · read models · consistency28What is a transaction and what does ACID mean?Easytransactions · acid · consistency29What are transaction isolation levels and their anomalies?Hardisolation levels · mvcc · concurrency30How do database locks work and how do you avoid contention?Hardlocking · contention · concurrency31What causes a deadlock and how do you handle it?Harddeadlocks · locking · retries32What are stored procedures and when should you use them?Mediumstored procedures · plpgsql · business logic33How do triggers work and what are the risks?Mediumtriggers · auditing · side effects34What is a database view and when should you use one?Easyviews · abstraction · security35What is a materialized view and how do you refresh it?Mediummaterialized views · caching · refresh36How do you implement pagination efficiently?Mediumpagination · limit offset · keyset37How do you perform an upsert safely?Mediumupsert · on conflict · concurrency38What is the difference between DELETE and TRUNCATE?Easydelete · truncate · ddl39How do you approach SQL performance tuning?Hardperformance tuning · indexes · query plans40What are common SQL mistakes in production?Mediumsql pitfalls · correctness · performance
Reading is step one
Now say it out loud.
Understanding an answer and delivering it under pressure are different skills. Rehearse this topic in a live SQL mock interview and get scored feedback on depth, clarity and confidence.