Skip to content

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. 1.In standard SQL, what does the expression NULL = NULL evaluate to?

    Medium

    null-handlingsql-syntax

  2. 2.In a query that uses GROUP BY with an aggregate function, what is the difference between filtering with WHERE and filtering with HAVING?

    Medium

    group-byquery-syntax

  3. 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?

    Easy

    joinsquery-syntax

  4. 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?

    Medium

    indexesperformance

  5. 5.In the context of database transactions, what is a 'dirty read'?

    Medium

    transactionsisolation-levels

  6. 6.This query is run: SELECT department, COUNT(*) FROM employees GROUP BY department; Why does department need to appear in the GROUP BY clause?

    Medium

    group-byaggregation

  7. 7.Explain the difference between INNER JOIN and LEFT JOIN, with an example.

    Easy

    joinsfundamentals

  8. 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?

    Medium

    joinsone-to-manyaggregation

  9. 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.

    Hard

    indexesinternals

  10. 10.Explain the difference between UNION and UNION ALL, and when you'd choose one over the other.

    Easy

    set-operationsquery-syntax

  11. 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.

    Medium

    group-byaggregationduplicates

  12. 12.Explain what a correlated subquery is, how it differs from a regular (non-correlated) subquery, and give an example.

    Hard

    subqueriesquery-syntax

← All interview prep categories