Why does this query return no rows even though the column contains NULLs?
SELECT * FROM t WHERE val = NULL;Read the full question →SQL is the query language every relational database speaks. Interviews test whether you can reason about set semantics, not just write SELECTs.
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.
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.
SELECT * FROM t WHERE val = NULL;Read the full question →-- A:
SELECT * FROM customers c
WHERE c.id IN (SELECT o.customer_id FROM orders o);
-- B:
SELECT * FROM customers c
WHERE EXISTS (SELECT 1 FROM orders o WHERE o.customer_id = c.id);Read the full question →-- scores: 10, NULL, 30
SELECT AVG(score) FROM scores;Read the full question →SELECT COUNT(salary), COUNT(*) FROM staff;Read the full question →-- 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 →SELECT * FROM (
SELECT e.*, <FN>() OVER (PARTITION BY dept ORDER BY salary DESC) AS rnk
FROM emp e
) s WHERE rnk = 1;Read the full question →SELECT name FROM users WHERE name LIKE 'a%';Read the full question →SELECT * FROM t WHERE val BETWEEN 20 AND 10;Read the full question →UPDATE products
SET price = price * 1.1
WHERE category = 'books';Read the full question →SELECT a.id
FROM a
INNER JOIN b ON a.code = b.code;
-- both a.code and b.code are NULL in some rowsRead the full question →CREATE TABLE t (
id SERIAL PRIMARY KEY,
name TEXT
);Read the full question →SELECT c.name, o.total
FROM customers c
LEFT JOIN orders o ON c.id = o.customer_id
WHERE o.total > 100;Read the full question →SELECT name, price * 2 AS doubled
FROM products
ORDER BY doubled DESC;Read the full question →SELECT name
FROM products
WHERE price > (SELECT AVG(price) FROM products);Read the full question →CREATE TABLE "Orders" (id int);Read the full question →SELECT 'A' AS grade, count(*)
FROM students;Read the full question →-- price column values: 10, 20, NULL, 30
SELECT * FROM items WHERE price BETWEEN 10 AND 30;Read the full question →SELECT *
FROM products
WHERE category IN ('books', 'toys', NULL);Read the full question →SELECT name FROM users WHERE country != 'US';Read the full question →SELECT department, name, COUNT(*)
FROM employees
GROUP BY department;Read the full question →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.
50 distinct SQL topics are tagged across the library. These are the real topic labels stored on the questions, not a hand-written list.
…