Top SQL Data Manipulation Interview Questions
SQL data manipulation is one of the most commonly tested skills in technical interviews for data roles. Companies like Meta, Google, Amazon, and other top tech firms use SQL questions to evaluate your ability to query, transform, and analyze data effectively. In a typical data manipulation interview, you'll be asked to write queries that JOIN multiple tables, aggregate data using GROUP BY and window functions, handle NULL values, and transform data using CASE statements and CTEs. Interviewers assess not just whether your query works, but also its efficiency, readability, and how well you communicate your approach. Whether you're preparing for a Data Scientist, Data Analyst, Data Engineer, or Analytics Engineer role, mastering SQL data manipulation is essential. The questions in this collection cover real interview problems from top companies, ranging from basic JOINs to complex multi-step transformations.
Questions by SQL Concept
JOIN
INNER, LEFT, RIGHT, FULL OUTER JOINs - combine data from multiple tables efficiently.
Window Functions
ROW_NUMBER, RANK, DENSE_RANK, LAG, LEAD for advanced analytics.
CTE & Subqueries
Common Table Expressions and subqueries for readable, modular SQL.
Aggregation
COUNT, SUM, AVG, MIN, MAX with GROUP BY for data summarization.
CASE WHEN
Conditional logic for data transformation and categorization.
Date/Time
Date arithmetic, timestamps, and time zone conversions.
String Functions
CONCAT, SUBSTRING, UPPER, LOWER, TRIM, and pattern matching.
NULL Handling
NULL semantics, COALESCE, NULLIF, and proper NULL comparisons.
UNION & Set Operations
Combine result sets with UNION, UNION ALL, INTERSECT, and EXCEPT.
HAVING Clause
Filter aggregated results with GROUP BY and HAVING for post-aggregation conditions.
Common Patterns in Interviews
Top-N per Group
Find the top N records within each group using ROW_NUMBER() or RANK() with PARTITION BY.
Deduplication
Remove duplicate records using ROW_NUMBER(), DISTINCT ON, or self-joins with aggregation.
Rolling MAU/WAU
Calculate rolling active users using window functions with date range conditions.
Retention Cohorts
Track user retention by joining signup dates with subsequent activity dates.
Funnel Conversion
Measure drop-off at each stage using conditional aggregation or CTEs.
Sessionization
Group events into sessions using LAG/LEAD window functions with running sum.
Common Pitfalls to Avoid
Join Explosion
Multiplying rows when joining without proper cardinality. Always verify join conditions.
WHERE vs ON
For OUTER JOINs, WHERE filters after the join, ON filters during. Know the difference.
NULL Semantics
NULL != NULL. Use IS NULL or IS NOT NULL for comparisons.
Time Zones
DATE truncation can give unexpected results without timezone awareness.
Integer Division
5/2 = 2, not 2.5. Cast to DECIMAL or FLOAT for accurate division.