Interview questions
Predict the result, find the errors, explain the solution. You can read the questions without an account.
25 questions
How many orders does
COUNT(o.id)count for a customer with no orders?Predict the resultJOIN and row countsHow do you find unmatched rows, and why can
NOT INcause problems?ExplainJOIN and row countsHow does the optimizer choose the
JOINorder, and why do outer joins restrict it?ExplainJOIN and row countsWhat does
CONCATreturn when one argument isNULL?Predict the resultNULLFind the bugs: counting anonymous events
Find the errorsNULLCan you sort
SELECT DISTINCTby a column outside the select list?Predict the resultQuery execution orderDoes the database execute queries in logical order?
ExplainQuery execution orderCan you select a column outside
GROUP BYwhen grouping by the primary key?Predict the resultGROUP BY / HAVINGWhich columns can you select in a query with
GROUP BY?ExplainGROUP BY / HAVINGHow do you avoid double-counting when aggregating after a
JOIN?ExplainGROUP BY / HAVINGCan you nest an aggregate inside a window function:
SUM(COUNT(*)) OVER ()?Predict the resultWindow functionsWhat does grouping by
id - ROW_NUMBER()find?Predict the resultWindow functionsWhat is a window frame, and how does
ROWSdiffer fromRANGE?ExplainWindow functionsHow do you calculate the median salary for each department using window functions?
ExplainWindow functionsHow many rows does
FETCH FIRST 2 ROWS WITH TIESreturn?Predict the resultDuplicates and top NFind the bugs: Second-highest salary in each department
Find the errorsDuplicates and top NHow do you paginate when the sort key can change?
ExplainDuplicates and top NHow many employees from
Saleswill this query find?Predict the resultSubqueries, CTEs, EXISTS / IN, UNIONHow does a CTE differ from a subquery, and is it materialized?
ExplainSubqueries, CTEs, EXISTS / IN, UNIONWhen can you push a filter into a subquery?
ExplainSubqueries, CTEs, EXISTS / IN, UNIONHow do data-skipping indexes work in ClickHouse?
ExplainIndexesWhy doesn't PostgreSQL use a parallel execution plan?
ExplainEXPLAIN and optimization