We use analytics and advertising cookies to understand how the site is used and whether our ads on Facebook, Instagram and Microsoft search (Bing) work. They are set only if you accept. See our Privacy Policy for details.
Practice SQL interview questions on joins and NULL handling, window functions, GROUP BY and HAVING, CTEs and subqueries, query performance and the differences between PostgreSQL, MySQL and SQL Server.
Answer a real SQL interview question before you browse the list. No signup needed.
Product data arrives in three normalised source tables: product, subcategory and category. The reporting model needs a single product dimension, and a product's category history must be kept when it changes. How should the data be prepared?
Practice in a session
10 questions from SQL, one after another, then your score and streak.
Joins (and what an outer join does to rows with no match), NULL handling, GROUP BY with HAVING, window functions such as ROW_NUMBER, RANK and LAG, CTEs and subqueries, and reading a query plan. Data roles add date arithmetic, conditional aggregation and deduplication; backend roles add indexes, transactions and locking.
SQL uses three-valued logic: a comparison with NULL is UNKNOWN, not false, so WHERE col <> 'x' silently drops NULL rows and NOT IN with a NULL in the list returns nothing. COUNT(col) skips NULLs while COUNT(*) does not, and an outer join produces NULLs that a later WHERE clause can quietly turn back into an inner join.
GROUP BY collapses each group into one row. A window function computes over a set of related rows but keeps every input row, so you can show each order next to its customer's running total or rank. PARTITION BY sets the group, ORDER BY sets the sequence, and the frame clause (ROWS or RANGE) sets which rows a running aggregate includes.
Most questions are portable ANSI SQL, but dialects differ in places interviewers like to probe: LIMIT vs TOP vs FETCH FIRST, string concatenation, date functions, upserts (ON CONFLICT vs ON DUPLICATE KEY vs MERGE) and how GROUP BY treats non-aggregated columns. Say which dialect you are writing and note where it would differ.
Talk about indexes that match the filter and join columns, why wrapping an indexed column in a function makes the predicate non-sargable, when the planner prefers a scan, and how to read EXPLAIN output. Mention avoiding SELECT * in hot paths and checking row estimates against actual rows when a plan looks wrong.