Skip to main content
Journey Uncommon Logo
JourneyUncommon
SQL · PRACTICE

SQL interview questions.

SQL is the query language every relational database speaks. Interviews test whether you can reason about set semantics, not just write SELECTs.

587questions
105easy
236medium
246hard

Join semantics with NULLs, GROUP BY versus window functions, index selectivity, isolation levels, and reading a query plan.

Where it shows up: Backend, data engineering, analytics, and any role that touches a production database.

Sample SQL questions

Twenty real SQL questions from the library, code snippet included. Nothing here is paraphrased for search engines. It is the same text a signed-in user sees.

mediumcorrelated subqueries

You want each employee whose salary is the maximum within their own department. Which correlated form is correct?

-- Goal: keep only rows that are the dept max
-- Option A
SELECT e.* FROM emp e
WHERE e.salary = (SELECT MAX(x.salary) FROM emp x WHERE x.dept_id = e.dept_id);
-- Option B
SELECT e.* FROM emp e
WHERE e.salary >= ALL (SELECT x.salary FROM emp x);
-- Option C
SELECT e.* FROM emp e
WHERE e.salary = (SELECT MAX(x.salary) FROM emp x);
-- Option D
SELECT e.* FROM emp e
WHERE EXISTS (SELECT 1 FROM emp x WHERE x.salary > e.salary);
Read the full question →
Sign in to answer

Everything above is free to read. Answering needs a free account.

We keep the correct answer, the explanation and the scoring behind sign-in so the platform stays honest, which is why the answer options and the worked explanation for every SQL question stay behind a free account. Signing in is free and takes a few seconds.

SQL topics covered

50 distinct SQL topics are tagged across the library. These are the real topic labels stored on the questions, not a hand-written list.

  • window functions ROW_NUMBER RANK (30)
  • nested-loop join (24)
  • isolation levels and anomalies (24)
  • composite and partial indexes (23)
  • table bloat and VACUUM (22)
  • the query planner optimizer (22)
  • UNION vs UNION ALL (17)
  • correlated subqueries (16)
  • JSONB querying (16)
  • aggregate functions (15)
  • CTEs WITH (15)
  • self-joins (15)
  • pivot conditional aggregation (15)
  • hash join (15)
  • transactions BEGIN COMMIT (14)
  • reading EXPLAIN ANALYZE (14)
  • statistics and cardinality estimation (14)
  • recursive CTEs (14)
  • EXISTS vs IN (13)
  • covering indexes (13)
  • MVCC and row versions (13)
  • merge join (13)
  • row vs table locking (13)
  • INNER JOIN (12)
  • B-tree index internals (12)
  • index-only scans (12)
  • upserts ON CONFLICT MERGE (12)
  • SELECT and WHERE (11)
  • GROUP BY and HAVING (11)
  • views and materialized views (11)
  • query plan cache prepared plans (11)
  • LEFT and RIGHT JOIN (10)
  • ORDER BY and LIMIT (10)
  • stored procedures functions (10)
  • INSERT UPDATE DELETE (9)
  • triggers (9)
  • the write-ahead log WAL (9)
  • dirty phantom non-repeatable reads (9)
  • DISTINCT (6)
  • IN and BETWEEN (6)
  • generated columns (6)
  • aliases AS (3)
  • CREATE TABLE (3)
  • the write-ahead log (WAL) (3)
  • dirty / phantom / non-repeatable reads (3)
  • NULL and IS NULL (2)
  • LIKE pattern matching (2)
  • primary and foreign keys (2)
  • CASE WHEN (2)
  • simple subqueries (1)

Search and filter every SQL question

Difficulty