SQL interview questions for data engineers
Joins, windows, NULL handling, indexes, and common interview SQL patterns. 49 questions with full answers, written for freshers. All topics
Tricky Output & Semantics (10)
- COUNT(DISTINCT) with NULLs
- NOT IN with a NULL in the subquery
- Row count after joining on duplicate keys
- Filtering the right table in a LEFT JOIN
- Integer division and rounding surprises
- Aggregates over an empty set
- Default window frame with ORDER BY
- GROUP BY with non-aggregated columns
- DISTINCT vs GROUP BY
- String comparison, case and trailing spaces
Subqueries, CTEs & Query Structure (6)
Writes, Transactions & Keys (6)
Performance & Internals (7)
Scenario Patterns (explain the approach, small SQL) (20)
- Nth highest salary per department
- Find and delete duplicate rows
- Latest record per customer
- Consecutive days streak (gaps and islands)
- Month-over-month growth
- Rolling 7-day average
- Customers who bought A but not B
- Overlapping date ranges
- Pivot rows to columns without PIVOT
- Sessionize click events
- Funnel conversion in SQL
- Top N per group
- Incremental load with a watermark in SQL
- Reconcile 2 tables
- Employees earning more than their manager
- Fill missing dates in a report
- Median and percentiles in SQL
- Query JSON columns
- UNNEST and arrays
- Percentage of total in SQL