SQL Interview Questions and Answers

SQL screens begin with query fluency: the join types and when each is right, GROUP BY with HAVING, subqueries versus CTEs, and window functions such as ROW_NUMBER, RANK and running totals. You are usually given a small schema and asked to write the query, then to explain its cost.

Deeper rounds cover how the database executes a query: indexes (B-tree, composite, covering), reading an execution plan, why a query is slow, transactions, ACID and isolation levels (dirty reads, phantom reads, deadlocks), and normalisation versus denormalisation for real workloads.

Questions

Related

Frequently asked questions

What SQL topics come up most in interviews?

Joins, aggregation with GROUP BY and HAVING, window functions, subqueries and CTEs, indexing and query plans, transactions and isolation levels, and schema design.

What is the difference between WHERE and HAVING?

WHERE filters rows before grouping; HAVING filters groups after aggregation, so it can use aggregate functions like COUNT or SUM.

How do I make a slow query faster?

Read the execution plan, check that filters and joins can use an index, avoid functions on indexed columns, select only the columns you need and consider a covering or composite index.