← 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

Ordered so the most useful questions for learning each pattern come first.

#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πŸ”’