SQL interview questions
100 Data Engineering practice questions. Read what a strong answer covers, then practise it out loud against the clock.
Practise SQL questionsBeginner
- Average looks too high
- Bucketing customers by spend
- CASE expressions
- Case-insensitive search
- Common date functions
- Common SQL constraints
- COUNT(*) vs COUNT(column) vs COUNT(DISTINCT)
- CTE vs subquery
- Customers who never ordered
- DELETE vs TRUNCATE vs DROP
- Deleting duplicates and keeping one
- DISTINCT vs GROUP BY
- Employees earning more than their manager
- Finding duplicate records
- Handling NULLs in SQL
- How GROUP BY works
- Join missing matches due to messy keys
- Latest order per customer
- Logical order of SQL execution
- Monthly sales totals
- Ordered in January but not February
- Orders per weekday
- Percent of total per category
- Primary key vs foreign key
- Row counts don't match between source and target
- Second highest salary
- Self join
- Top five products by revenue
- Totals doubled after a join
- Types of SQL joins
- UNION vs UNION ALL
- What a view is
- What an index does
- WHERE vs HAVING
Intermediate
- Anti-join patterns
- Conversion funnel
- Correlated subqueries
- Customers who bought both A and B
- Customers whose spend grew every month
- Day-7 retention
- EXISTS vs IN vs NOT IN
- Filling date gaps with a date spine
- Finding missing invoice numbers
- GROUPING SETS, ROLLUP and CUBE
- INTERSECT and EXCEPT
- LAG and LEAD
- Latest version from a change log
- Median order value per country
- MERGE statement for upserts
- Month-over-month growth
- Monthly cohort retention
- Overlapping bookings
- Percentiles and NTILE
- Pivot and unpivot
- Point-in-time join with SCD2
- QUALIFY clause
- Recursive CTEs
- ROW_NUMBER vs RANK vs DENSE_RANK
- ROWS vs RANGE in window frames
- Running balance per account
- Running totals and window frames
- Sales by quarter as columns
- Seven-day moving average
- String aggregation
- Top three products per category
- Users who logged in three days in a row
- What window functions are
Experienced
- Applying CDC changes with SQL
- Approximate aggregate functions
- Currency conversion with daily rates
- Daily balance from sparse transactions
- Daily totals don't match between teams
- Data skew in distributed SQL
- Deadlocks
- Deduplicating events with late duplicates
- Deduplication strategies at scale
- Detecting rapid repeated transactions
- Distinct users over billions of rows
- Fact arrives before its SCD2 dimension change
- Full reporting chain in an org chart
- Gaps and islands problems
- How columnar storage changes SQL habits
- Idempotent SQL loads
- Join algorithms
- Join slowed by a skewed key
- NULLs in joins and aggregates
- Optimizing a slow reporting query
- Proving two tables are identical
- Query suddenly returns zero rows
- Reading an execution plan
- Safe daily reload of a partition
- Sargable predicates
- SCD Type 2 load in pure SQL
- Session metrics from clickstream
- Sessionization in SQL
- Slow lookup query on an OLTP database
- Statistics and cardinality estimates
- Table partitioning in SQL engines
- Timestamp types and time zones
- Transaction isolation levels