Interview Prep
SQL Interview Questions
Query-writing and database-reasoning questions asked in almost every technical interview that touches data.
12 of 12 SQL questions shown. Answers are hidden by default — try each one before revealing it.
1.In standard SQL, what does the expression NULL = NULL evaluate to?
Mediumnull-handlingsql-syntax
2.In a query that uses GROUP BY with an aggregate function, what is the difference between filtering with WHERE and filtering with HAVING?
Mediumgroup-byquery-syntax
3.Given tables customers and orders, consider this query: SELECT customers.name, orders.id FROM customers LEFT JOIN orders ON customers.id = orders.customer_id; What happens for a customer who has placed no orders?
Easyjoinsquery-syntax
4.You add an index on a column that is frequently used in WHERE clauses of a large, read-heavy table. What is the main trade-off of doing this?
Mediumindexesperformance
5.In the context of database transactions, what is a 'dirty read'?
Mediumtransactionsisolation-levels
6.This query is run: SELECT department, COUNT(*) FROM employees GROUP BY department; Why does department need to appear in the GROUP BY clause?
Mediumgroup-byaggregation
7.Explain the difference between INNER JOIN and LEFT JOIN, with an example.
Easyjoinsfundamentals
8.The orders table has one row per order (columns: id, customer_name). The order_items table has one row per item within an order (columns: id, order_id, product), so a single order can have several order_items rows. Consider: SELECT orders.id, orders.customer_name, order_items.product FROM orders JOIN order_items ON orders.id = order_items.order_id; If a particular order has 3 items, what does this query return for that order, and why? What problem could this cause if you later tried to SUM(orders.total) over this joined result?
Mediumjoinsone-to-manyaggregation
9.Explain the difference between a clustered index and a non-clustered index, and why a table can typically have only one clustered index but many non-clustered indexes.
Hardindexesinternals
10.Explain the difference between UNION and UNION ALL, and when you'd choose one over the other.
Easyset-operationsquery-syntax
11.How would you write a query to find duplicate rows in a table — for example, rows in a users table where the same email address appears more than once? Write the query and explain your approach.
Mediumgroup-byaggregationduplicates
12.Explain what a correlated subquery is, how it differs from a regular (non-correlated) subquery, and give an example.
Hardsubqueriesquery-syntax