Interview questions
Predict the result, find the errors, explain the solution. You can read the questions without an account.
Level: JuniorReset all
112 questions
How many rows does an
INNER JOINreturn when the join keys contain duplicates andNULL?Predict the resultJOIN and row countsDoes swapping the tables change the result of a
LEFT JOIN?Predict the resultJOIN and row countsFrom interview write-ups: T-BankHow many rows does a
CROSS JOINreturn when the tables containNULL?Predict the resultJOIN and row countsHow many rows will a join between employees and their managers return?
Predict the resultJOIN and row countsFind the bugs: employees and their managers
Find the errorsJOIN and row countsWhat types of
JOINare there, and when would you use each?ExplainJOIN and row countsWhich rows will a
JOINbetween orders and line items return after two filters?Predict the resultJOIN and row countsWho earns more than their manager in a
SELF JOIN?Predict the resultJOIN and row countsWhich pairs of customers from the same city will a
SELF JOINreturn?Predict the resultJOIN and row countsWhich rows will a
JOINbetween users and events return?Predict the resultJOIN and row countsFind the bugs: order number and customer name
Find the errorsJOIN and row countsWhat does
5 + NULLreturn?Predict the resultNULLFrom interview write-ups: T-BankWill
manager_id = NULLfind an employee with no manager?Predict the resultNULLWhat do
COUNT(*)andSUMreturn for a department with no employees?Predict the resultNULLWhat do
COUNT(*),COUNT(x), andCOUNT(DISTINCT x)return?Predict the resultNULLFind the bugs: employees missing a department or salary
Find the errorsNULLWhat does
COALESCEreturn when a customer's city is missing?Predict the resultNULLHow does
CASEclassify an employee with a missing salary?Predict the resultNULLWhat does
NULLIFreturn for employee salaries?Predict the resultNULLFind the bugs: listing customers from Berlin
Find the errorsNULLCan you use a
SELECTalias inWHERE?Predict the resultQuery execution orderWill
SUMtotal only three orders if you addLIMIT 3?Predict the resultQuery execution orderWhat does
ORDER BYusing an alias return withLIMITandOFFSET?Predict the resultQuery execution orderFind the bugs: employees earning above the company average
Find the errorsQuery execution orderWhich runs last:
SELECT,FROM,WHERE, orGROUP BY?ExplainQuery execution orderFrom interview write-ups: T-BankWhich statuses do
DISTINCTandLIMIT 2return?Predict the resultQuery execution orderWhich groups remain after the
WHEREfilter?Predict the resultQuery execution orderWhich departments remain after
LEFT JOINandWHERE?Predict the resultQuery execution orderFind the bugs: the three highest-value paid orders
Find the errorsQuery execution orderWill
GROUP BYinclude a department with no employees?Predict the resultGROUP BY / HAVINGDoes
MAX(name)return the name of the highest-paid employee?Predict the resultGROUP BY / HAVINGWill a query using
GROUP BYrun ifSELECTincludes an ungrouped column?Predict the resultGROUP BY / HAVINGFind the bugs: paid orders and unique buyers by month
Find the errorsGROUP BY / HAVINGFind the bugs: order counts and totals by customer
Find the errorsGROUP BY / HAVINGWhat's the difference between
WHEREandHAVING?ExplainGROUP BY / HAVINGFind the bugs: minimum paid order amount per customer
Find the errorsGROUP BY / HAVINGHow do you sum item quantities in groups defined by a condition?
Predict the resultGROUP BY / HAVINGHow does
GROUP BYaggregate orders with different statuses?Predict the resultGROUP BY / HAVINGWhich customers pass the
HAVINGcheck on order amounts?Predict the resultGROUP BY / HAVINGWhat numbers will
ROW_NUMBER,RANK, andDENSE_RANKassign to employees in department 2?Predict the resultWindow functionsHow many rows will a query using
SUM(salary) OVER (PARTITION BY department_id)return?Predict the resultWindow functionsWhat does
LAGreturn for the first row?Predict the resultWindow functionsFind the bugs: Show each employee's salary alongside their department's average
Find the errorsWindow functionsFind the bugs: running total of payments for each customer
Find the errorsWindow functionsWhat is a window function, and how does
PARTITION BYdiffer fromGROUP BY?ExplainWindow functionsWhat's the difference between
ROW_NUMBER,RANK, andDENSE_RANK?ExplainWindow functionsWhat will this
LEADquery return?Predict the resultWindow functionsHow does
ROW_NUMBERwork when event types alternate?Predict the resultWindow functionsFind the bugs: two most recent events per user
Find the errorsWindow functionsWhat will
FIRST_VALUEandMINreturn for a customer's orders?Predict the resultWindow functionsWhich duplicates does
GROUP BY … HAVING COUNT(*) > 1find?Predict the resultDuplicates and top NWill
LIMIT 1 OFFSET 1return the second-highest salary?Predict the resultDuplicates and top NFind the bugs: Count distinct events per user
Find the errorsDuplicates and top NHow do you find the second-highest salary?
ExplainDuplicates and top NWhich events will a query with
LIMITandOFFSETreturn?Predict the resultDuplicates and top NWhat remains after applying
UNION DISTINCTto two tables?Predict the resultDuplicates and top NFind the bugs: Deduplicating an event log
Find the errorsDuplicates and top NWhich row will
ROW_NUMBERkeep for each product?Predict the resultDuplicates and top NWhich city and order status pairs will
DISTINCTkeep?Predict the resultDuplicates and top NHow many January orders does
BETWEEN '2026-01-01' AND '2026-01-31'find?Predict the resultDatesWhat do
CAST(created_at AS DATE) = …andcreated_at = CAST(… AS DATE)count?Predict the resultDatesFind the bugs: paid orders in February
Find the errorsDatesFind the bugs: hires by month
Find the errorsDatesWhich employees match
EXTRACT(DAY FROM hired_at) = 1?Predict the resultDatesHow many events fall within a five-minute window?
Predict the resultDatesWhich orders match the midnight-hour filter?
Predict the resultDatesFind the bugs: time of each customer's latest payment
Find the errorsDatesHow many departments does this
EXISTSquery return?Predict the resultSubqueries, CTEs, EXISTS / IN, UNIONFind the bugs: orders from Berlin customers
Find the errorsSubqueries, CTEs, EXISTS / IN, UNIONWhat's the difference between
UNIONandUNION ALL?ExplainSubqueries, CTEs, EXISTS / IN, UNIONWhat is a correlated subquery?
ExplainSubqueries, CTEs, EXISTS / IN, UNIONWho earns more than the highest-paid employee in
Sales?Predict the resultSubqueries, CTEs, EXISTS / IN, UNIONWhat does a subquery in the
SELECTlist return?Predict the resultSubqueries, CTEs, EXISTS / IN, UNIONWhich values does the nested query with
EXCEPTreturn?Predict the resultSubqueries, CTEs, EXISTS / IN, UNIONFind the bugs: orders with at least two line items
Find the errorsSubqueries, CTEs, EXISTS / IN, UNIONFind the bugs: a customer's two most recent orders
Find the errorsIndexesWhat is a database index, and why do we use one?
ExplainIndexesWhy doesn't
LIKE '%abc%'use a regular index?ExplainIndexesHow many rows does a non-unique index lookup return?
Predict the resultIndexesWhich salaries fall within a
BETWEENrange?Predict the resultIndexesWhich orders match the status and total filters?
Predict the resultIndexesFind the bugs: orders for two customer scenarios
Find the errorsIndexesHow does a hash index differ from a B-tree index?
ExplainIndexesWhat appears on the second page with
OFFSETif a new event arrives?Predict the resultEXPLAIN and optimizationWhat's the difference between
EXPLAINandEXPLAIN ANALYZE?ExplainEXPLAIN and optimizationWhat is the N+1 query problem?
ExplainEXPLAIN and optimizationWhat does a filter return after row numbering?
Predict the resultEXPLAIN and optimizationWhich employees match this name pattern?
Predict the resultEXPLAIN and optimizationWhat does
Sortmean in a query execution plan?ExplainEXPLAIN and optimizationWhy can
SELECT *slow down a query?ExplainEXPLAIN and optimizationWhat is a transaction, and what does ACID mean?
ExplainTransactions and locksWhy can't the application see your
UPDATE?ExplainTransactions and locksWhat is a deadlock, and how can you prevent one?
ExplainTransactions and locksWhich sessions are idle with an open transaction?
Predict the resultTransactions and locksFind the bugs: paid orders with no items
Find the errorsTransactions and locksHow does
autocommitaffect multiple statements?ExplainTransactions and locksHow would a QA engineer test the atomicity of an order operation?
ExplainTransactions and locksCan you insert a second
NULLinto a column with aUNIQUEconstraint?Predict the resultDDL, keys, and normalizationFind the bugs: SQL newsletter subscribers
Find the errorsDDL, keys, and normalizationWhat are primary keys, unique keys, and foreign keys?
ExplainDDL, keys, and normalizationWhat's the difference between
DELETE,TRUNCATE, andDROP?ExplainDDL, keys, and normalizationFind the bugs: checking data before changing a column
Find the errorsDDL, keys, and normalizationCan you add a customer with an existing name?
Predict the resultDDL, keys, and normalizationCan you insert
NULLinto a required column?Predict the resultDDL, keys, and normalizationWill the schema allow a negative item quantity?
Predict the resultDDL, keys, and normalizationFind the bugs: validating order statuses before a migration
Find the errorsDDL, keys, and normalizationWhy use
DECIMALinstead ofFLOATfor money?ExplainDDL, keys, and normalizationHow do
DEFAULT,CHECK, andNOT NULLwork together?ExplainDDL, keys, and normalizationWhat happens when you insert an empty string into a required field?
Predict the resultDDL, keys, and normalization