โ† 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#4Highest-Paid Employee in Each DepartmentWindow functionsMediumFreeUnlock 48 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๐Ÿ”’#14Delete Duplicate RowsChanging dataMedium๐Ÿ”’#17Month-over-Month Growth (LAG)Window functionsMedium๐Ÿ”’#20Each Customer's Second OrderWindow functionsMedium๐Ÿ”’#213-Order Moving AverageWindow functionsMedium๐Ÿ”’#25Pivot Order Statuses into ColumnsCASE & NULLMedium๐Ÿ”’#27Each Category's Share of RevenueWindow functionsMedium๐Ÿ”’#36Subquery vs JOIN vs CTESubqueriesMedium๐Ÿ”’#37Employees Paid Above Their Department AverageSubqueriesMedium๐Ÿ”’#38EXISTS vs INSubqueriesMedium๐Ÿ”’#39How do indexes work?Indexes & transactionsMedium๐Ÿ”’#41Normalization (1NF, 2NF, 3NF)Schema designMedium๐Ÿ”’#42ACID transactionsIndexes & transactionsMedium๐Ÿ”’#44SQL injection and how to prevent itIndexes & transactionsMedium๐Ÿ”’#47SQL's logical order of executionBasicsMedium๐Ÿ”’#48Pagination (LIMIT/OFFSET vs keyset)Sorting & limitsMedium๐Ÿ”’#50Days Between a Customer's OrdersWindow functionsMedium๐Ÿ”’#53Split Employees into Salary QuartilesWindow functionsMedium๐Ÿ”’#54Cancellation Rate per CustomerCASE & NULLMedium๐Ÿ”’#58Upsert (insert or update)Changing dataMedium๐Ÿ”’#59Update Using Another TableChanging dataMedium๐Ÿ”’#60Design a Table with ConstraintsSchema designMedium๐Ÿ”’#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๐Ÿ”’#75Each Customer's Most Recent OrderWindow functionsMedium๐Ÿ”’#78Salary Gap to the Department's Top EarnerWindow functionsMedium๐Ÿ”’#80Revenue by Category and MonthGroup byMedium๐Ÿ”’#82Replication vs shardingIndexes & transactionsMedium๐Ÿ”’#84Schema migrations in productionSchema designMedium๐Ÿ”’#85Choosing column types (money, time, IDs)Schema designMedium๐Ÿ”’#86JSON columns in a relational databaseSchema designMedium๐Ÿ”’#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๐Ÿ”’#94INTERSECT and EXCEPTBasicsMedium๐Ÿ”’#95Row With the Max Value per Group (without window functions)JoinsMedium๐Ÿ”’#98Combine Rows into a List (GROUP_CONCAT / STRING_AGG)Group byMedium๐Ÿ”’#99Aggregate of AggregatesSubqueriesMedium๐Ÿ”’