Interview preparation
How to Prepare for SQL Interview Questions
A practical SQL interview preparation plan: which concepts to master, the question patterns to practice, and how to structure your answers — for data analyst, data engineer, and backend interviews.
What interviewers actually test
Most SQL interviews test a small set of patterns repeatedly: filtering with WHERE, grouping and aggregating, joining two or more tables, and — at the senior level — window functions and multi-step problems expressed with CTEs.
Mastery looks like recognizing the pattern in the first sentence of the problem: 'per department' means GROUP BY, 'previous day' means LAG or a self join, 'top N per group' means a window function.
A two-week practice sequence
Week one: SELECT, WHERE, NULL handling, sorting, then GROUP BY, HAVING, and aggregates. Week two: JOINs, self joins, subqueries, CTEs, then window functions — ranking, running totals, and gaps and islands.
Practice each pattern until you can write the skeleton query from memory, then move on. Depth on patterns beats breadth on random questions.
How to present your answer
State the approach in one sentence before writing SQL. Write the query, then walk through what each clause does and why. Mention edge cases — NULLs, duplicates, ties — unprompted. Interviewers reward candidates who surface edge cases themselves.
Practice questions
- easyActive Users Per Day
- easyArticle Views I
- easyAverage Process Time Per Machine
- easyBig Countries
- easyClasses With At Least 5 Students
- easyCustomers Without Orders
- easyDuplicate Emails
- easyEmployee Bonus
- easyEmployees Earning More Than Their Manager
- easyFind Customer Referee
- easyInvalid Tweets
- easyRecyclable and Low Fat Products
- easyRising Temperature
- easySubjects Taught By Each Teacher
- easyVisits Without Transactions
- mediumConsecutive Login Days
- mediumConsecutive Numbers
- mediumCustomers Who Bought All Products
- mediumDepartments by Average Salary
- mediumFirst and Last Order Per Customer
- mediumGame Play Analysis IV
- mediumImmediate Food Delivery
- mediumLatest Event Per User
- mediumLongest Login Streak
- mediumMonthly Sales Ranking
- mediumNth Highest Salary
- mediumOrders Gap Analysis
- mediumPercentage of Total Sales
- mediumPivot Quarterly Sales
- mediumRank Scores
- mediumRunning Total
- mediumSeven-Day Rolling Average
- mediumUsers With the Most Friends
- hardTop Three Per Category