โ† All topics

๐Ÿ—„ Interview Prep

SQL & Databases

Joins, GROUP BY, subqueries, CTEs and window functions, run on real tables in your browser. Asked for back-end, data and full-stack roles.

100 questions, most asked first

Ranked by how often each question comes up in real interviews. #1 is the most common.

#1Second-Highest SalarySubqueriesMediumFree#2Nth-Highest Salary (with DENSE_RANK)Window functionsMediumFree#3Customers Who Never OrderedJoinsEasyFree#4Highest-Paid Employee in Each DepartmentWindow functionsMediumFree#5Find Duplicate EmailsGroup byEasyFree#6Employees Earning More Than Their ManagersSelf joins & CTEsEasyFree#7Average Salary by DepartmentGroup byEasyFree#8Top 3 Salaries in Each DepartmentWindow functionsHardFree#9INNER vs LEFT vs RIGHT vs FULL JOINJoinsEasyFree#10WHERE vs HAVINGGroup byEasyFreeUnlock 90 more SQL & Databases questions ยท all 1,200 questions for $39/year (about 11ยข a day)See full access#11Rank ScoresWindow functionsMedium๐Ÿ”’#12Running Total of RevenueWindow functionsMedium๐Ÿ”’#13Number of Orders per Customer (Including Zero)JoinsEasy๐Ÿ”’#14Delete Duplicate RowsChanging dataMedium๐Ÿ”’#15Users With 3+ Consecutive Login DaysWindow functionsHard๐Ÿ”’#16Monthly RevenueDates & stringsEasy๐Ÿ”’#17Month-over-Month Growth (LAG)Window functionsMedium๐Ÿ”’#18Products Never OrderedSubqueriesEasy๐Ÿ”’#19Customers Who Bought From Every CategoryGroup byHard๐Ÿ”’#20Each Customer's Second OrderWindow functionsMedium๐Ÿ”’#213-Order Moving AverageWindow functionsMedium๐Ÿ”’#22Employees Hired in a Date RangeDates & stringsEasy๐Ÿ”’#23Handling NULLs with COALESCECASE & NULLEasy๐Ÿ”’#24Salary Bands with CASECASE & NULLEasy๐Ÿ”’#25Pivot Order Statuses into ColumnsCASE & NULLMedium๐Ÿ”’#26Top Customer by Total SpendSorting & limitsEasy๐Ÿ”’#27Each Category's Share of RevenueWindow functionsMedium๐Ÿ”’#28Each Customer's First Order DateAggregatesEasy๐Ÿ”’#29Next-Day RetentionSelf joins & CTEsHard๐Ÿ”’#30Daily Active UsersAggregatesEasy๐Ÿ”’#31Who Referred the Most Customers?Self joins & CTEsEasy๐Ÿ”’#32Org Chart with a Recursive CTESelf joins & CTEsHard๐Ÿ”’#33Departments With No EmployeesJoinsEasy๐Ÿ”’#34Employees Without a DepartmentFilteringEasy๐Ÿ”’#35UNION vs UNION ALLBasicsEasy๐Ÿ”’#36Subquery vs JOIN vs CTESubqueriesMedium๐Ÿ”’#37Employees Paid Above Their Department AverageSubqueriesMedium๐Ÿ”’#38EXISTS vs INSubqueriesMedium๐Ÿ”’#39How do indexes work?Indexes & transactionsMedium๐Ÿ”’#40Primary keys and foreign keysSchema designEasy๐Ÿ”’#41Normalization (1NF, 2NF, 3NF)Schema designMedium๐Ÿ”’#42ACID transactionsIndexes & transactionsMedium๐Ÿ”’#43Transaction isolation levelsIndexes & transactionsHard๐Ÿ”’#44SQL injection and how to prevent itIndexes & transactionsMedium๐Ÿ”’#45COUNT(*) vs COUNT(column) vs COUNT(DISTINCT)AggregatesEasy๐Ÿ”’#46DISTINCT vs GROUP BYGroup byEasy๐Ÿ”’#47SQL's logical order of executionBasicsMedium๐Ÿ”’#48Pagination (LIMIT/OFFSET vs keyset)Sorting & limitsMedium๐Ÿ”’#49Extract email domainsDates & stringsEasy๐Ÿ”’#50Days Between a Customer's OrdersWindow functionsMedium๐Ÿ”’#51Median SalaryWindow functionsHard๐Ÿ”’#52The Most Popular ProductAggregatesEasy๐Ÿ”’#53Split Employees into Salary QuartilesWindow functionsMedium๐Ÿ”’#54Cancellation Rate per CustomerCASE & NULLMedium๐Ÿ”’#55Average Order Value by CityAggregatesEasy๐Ÿ”’#56Customers Who Ordered in Consecutive MonthsSelf joins & CTEsHard๐Ÿ”’#57DELETE vs TRUNCATE vs DROPChanging dataEasy๐Ÿ”’#58Upsert (insert or update)Changing dataMedium๐Ÿ”’#59Update Using Another TableChanging dataMedium๐Ÿ”’#60Design a Table with ConstraintsSchema designMedium๐Ÿ”’#61What is a view?Schema designEasy๐Ÿ”’#62Stored procedures and triggersSchema designMedium๐Ÿ”’#63OLTP vs OLAPIndexes & transactionsMedium๐Ÿ”’#64SQL vs NoSQLSchema designMedium๐Ÿ”’#65When to denormalizeSchema designMedium๐Ÿ”’#66How would you speed up a slow query?Indexes & transactionsMedium๐Ÿ”’#67The N+1 query problemJoinsMedium๐Ÿ”’#68What are window functions?Window functionsMedium๐Ÿ”’#69CTE vs subquery vs temporary tableSelf joins & CTEsMedium๐Ÿ”’#70Find Gaps in a SequenceWindow functionsMedium๐Ÿ”’#71Best-Selling Product in Each CategoryWindow functionsMedium๐Ÿ”’#72Customers Who Never CancelledGroup byEasy๐Ÿ”’#73City With the Most CustomersGroup byEasy๐Ÿ”’#74Orders Above the Average AmountSubqueriesEasy๐Ÿ”’#75Each Customer's Most Recent OrderWindow functionsMedium๐Ÿ”’#76Units Sold per Product (Including Zero)JoinsEasy๐Ÿ”’#77Hires per YearDates & stringsEasy๐Ÿ”’#78Salary Gap to the Department's Top EarnerWindow functionsMedium๐Ÿ”’#79Same-Day Duplicate EventsGroup byEasy๐Ÿ”’#80Revenue by Category and MonthGroup byMedium๐Ÿ”’#81Optimistic vs pessimistic lockingIndexes & transactionsHard๐Ÿ”’#82Replication vs shardingIndexes & transactionsMedium๐Ÿ”’#83Soft deletesSchema designEasy๐Ÿ”’#84Schema migrations in productionSchema designMedium๐Ÿ”’#85Choosing column types (money, time, IDs)Schema designMedium๐Ÿ”’#86JSON columns in a relational databaseSchema designMedium๐Ÿ”’#87Searching text with LIKEFilteringEasy๐Ÿ”’#88Filtering with IN and BETWEENFilteringEasy๐Ÿ”’#89Case-Insensitive Duplicate EmailsDates & stringsMedium๐Ÿ”’#90Cumulative Customer SignupsWindow functionsMedium๐Ÿ”’#91Subtotals with a Grand Total RowGroup byMedium๐Ÿ”’#92Pairs of Customers in the Same CitySelf joins & CTEsMedium๐Ÿ”’#93Every Combination with CROSS JOINJoinsEasy๐Ÿ”’#94INTERSECT and EXCEPTBasicsMedium๐Ÿ”’#95Row With the Max Value per Group (without window functions)JoinsMedium๐Ÿ”’#96Orders by Signup CohortGroup byHard๐Ÿ”’#97Copy Rows with INSERT โ€ฆ SELECTChanging dataEasy๐Ÿ”’#98Combine Rows into a List (GROUP_CONCAT / STRING_AGG)Group byMedium๐Ÿ”’#99Aggregate of AggregatesSubqueriesMedium๐Ÿ”’#100How to approach any SQL interview questionBasicsEasy๐Ÿ”’