SQL
387 practice items · needed by 22 roles
Easy 123Medium 156Hard 108
Coding problems
Practice questions
- Why React lists need keyseasy
- Stopping SQL injectioneasy
- Purpose of a database indexeasy
- Rows returned by a LEFT JOINeasy
- What a foreign key enforceseasy
- Atomicity in a money transfereasy
- COUNT and AVG with NULLseasy
- Filtering grouped resultseasy
- Duplicate emails despite a checkeasy
- What EXPLAIN tells youeasy
- Database user for the appeasy
- Building SQL from user inputeasy
- WHERE column = NULL finds nothingeasy
- COUNT(*) versus COUNT(column)easy
- Storing order times for two countrieseasy
- Rows come back in a new ordereasy
- Checking if any rows existeasy
- Which year is a leap yeareasy
- Month number in new Dateeasy
- Converting Dubai time to India timeeasy
- The N+1 query problemmedium
- Isolation levels and dirty readsmedium
- Offset or cursor paginationmedium
- Composite index column ordermedium
- Optimistic lock update hits 0 rowsmedium
- Index ignored for lower(email)medium
- Page view counter loses countsmedium
- Insert or update in one statementmedium
- Importing 100,000 rows slowlymedium
- Rows skipped with created_at cursorsmedium
- Joining two lists in memorymedium
- Adding one month to 31 Januarymedium
- Day count off by a fractionmedium
- Where NULLs go in PostgreSQL ORDER BYmedium
- Lost update on a wallet balancehard
- NOT IN with a NULL in the listhard
- Sorting by a user-chosen columnhard
- Parsing a date-only stringhard
- Rows missing across paginated pageshard
- Preventing SQL injectioneasy
- Listing users with zero orderseasy
- Comparing a column to NULLeasy
- What an index costseasy
- Moving credits between accountsmedium
- Composite index column ordermedium
- Birthday shows one day earlyhard
- Two agents edit one tickethard
- Items missing between pageshard
- NOT IN returns no rowshard
- Date decoding fails on millisecondshard
- Purpose of a primary keyeasy
- INNER JOIN vs LEFT JOINeasy
- DELETE vs TRUNCATEeasy
- Filtering rows where a value is NULLeasy
- COUNT(*) vs COUNT(column)easy
- What a foreign key enforceseasy
- WHERE vs HAVINGeasy
- View vs materialized vieweasy
- UNION vs UNION ALLeasy
- Row order without ORDER BYeasy
- Rejecting bad valueseasy
- NOT IN returns no rowseasy
- Counting rows with NULL phoneseasy
- NOT IN returns nothingmedium
- Checking if any row existsmedium
- ON CONFLICT needs a unique indexmedium
- CTE acts as an optimisation fencemedium
- FOR UPDATE with GROUP BY failsmedium
- FOR UPDATE on a join locks too muchhard
- Counting orders per customereasy
- Customers with no orderseasy
- Filtering groups in SQLeasy
- COUNT of a column with NULLseasy
- Getting the weekday from a date columneasy
- Latest order per customermedium
- Row count after a mergemedium
- Ranking with ties in SQLmedium
- NOT IN returns no rowsmedium
- Customers who never orderedmedium
- Showing UTC timestamps in Dubai timemedium
- Catching duplicate keys in a mergemedium
- Dates like 03/04/2026 in an Indian filemedium
- Columns called price_x and price_ymedium
- LEFT JOIN that acts like INNER JOINhard
- Merging an int key with a text keyhard
- NaN keys in a pandas mergehard
- Adding a month to 31 Januaryhard
- Business days for a Saudi officehard
- WHERE vs HAVINGeasy
- Which join keeps all customerseasy
- COUNT(*) vs COUNT(column)easy
- What a pivot table doeseasy
- Finding NULL valueseasy
- COUNT(DISTINCT) with NULLseasy
- Rows from an INNER JOINeasy
- UNION vs UNION ALLeasy
- AVG with a NULL valueeasy
- Bucketing with CASE WHENeasy
- Dividing two integers in SQLeasy
- Why this GROUP BY failseasy
- Does BETWEEN include the endseasy
- Matching text with LIKEeasy
- Top seller with ORDER BY and LIMITeasy
- What a primary key guaranteeseasy
- A date that should not changeeasy
- Days between two dateseasy
- Showing the weekday nameeasy
- Last day of the montheasy
- A running total columneasy
- Showing 0 instead of NULLeasy
- Full name comes out emptyeasy
- Rows from a CROSS JOINeasy
- DISTINCT with two columnseasy
- Column alias in WHERE failseasy
- Sorting by two columnseasy
- Window function vs GROUP BYeasy
- An empty OVER clauseeasy
- What PARTITION BY doeseasy
- RANK values for tied scoreseasy
- Filtering on ROW_NUMBER in WHEREeasy
- LAG on the first roweasy
- What LEAD returnseasy
- Each product's share of saleseasy
- Top 3 products in each categoryeasy
- Second highest salary with tieseasy
- A 3-day moving average frameeasy
- Salary vs department averageeasy
- Each customer's first product boughteasy
- Team size on every employee roweasy
- ORDER BY inside and outside OVEReasy
- Computing PERCENT_RANKeasy
- Computing CUME_DISTeasy
- Highest DENSE_RANK valueeasy
- Deleting duplicate rowseasy
- Total count beside a page of rowseasy
- Window functions in MySQLeasy
- Reusing a window aliaseasy
- Highest balance so fareasy
- Rows with a NULL regioneasy
- Looking two rows aheadeasy
- Sorting by a window valueeasy
- Revenue doubled after a joinmedium
- Latest order per customermedium
- Running total of salesmedium
- LEFT JOIN that lost customersmedium
- RANK vs DENSE_RANK after a tiemedium
- Month-over-month change with LAGmedium
- Share of paid orders in one querymedium
- Customers who never orderedmedium
- Grouping orders by monthmedium
- Counting repeat customers with a CTEmedium
- Rows after a pandas left mergemedium
- SUM over zero matching rowsmedium
- Sum that skips hidden rowsmedium
- Summing a column that has errorsmedium
- Weighted average pricemedium
- Month labels sort in the wrong ordermedium
- One month after 31 Januarymedium
- Working days in two weeksmedium
- Due date 3 working days latermedium
- Age in completed yearsmedium
- January shows two years togethermedium
- Order of CASE branchesmedium
- Customers listed many timesmedium
- Showing each employee's managermedium
- Each region's share of total salesmedium
- Counting paid orders returns all ordersmedium
- Bought in both January and Februarymedium
- Rows from GROUP BY ROLLUPmedium
- ROW_NUMBER in a WHERE clausemedium
- What QUALIFY is formedium
- Running total that resets per customermedium
- Computing a running totalmedium
- Value of a 3-row moving averagemedium
- 7-row average with missing daysmedium
- Splitting clicks into sessionsmedium
- Grouping consecutive datesmedium
- Share of total after GROUP BYmedium
- Previous order from another customermedium
- Best seller per city with tiesmedium
- The third purchase amountmedium
- Running count of distinct customersmedium
- Month-over-month growth valuemedium
- Tagging rows with a cohort monthmedium
- Counting ticket status changesmedium
- Finding missing invoice numbersmedium
- LAG in pandasmedium
- YTD for an April–March yearmedium
- Reusing one window definitionmedium
- Filtering before or after the windowmedium
- A centred 3-day averagemedium
- A date-based 7-day framemedium
- Day-over-day change with gapsmedium
- LAG on raw order rowsmedium
- A window inside a windowmedium
- Year-over-year with LAG 12medium
- Spotting customers who lapsedmedium
- Products making 80% of revenuemedium
- Window function after GROUP BYmedium
- Marking duplicates in an UPDATEmedium
- Speeding up a ranking querymedium
- RANK in pandasmedium
- Latest row with DISTINCT ONmedium
- DISTINCT and a window countmedium
- NOT IN returns nothinghard
- Average of averageshard
- Daily numbers do not matchhard
- Running total with tied dateshard
- Filter inside the ON clausehard
- Not-equal filter loses rowshard
- PERCENTILE_CONT vs PERCENTILE_DISChard
- NTILE with 10 rowshard
- Latest order changes between runshard
- Click-through rate with zero impressionshard
- Adding up daily active usershard
- Filtering NaN with == in pandashard
- GROUP BY with NULL citieshard
- Dates swapped when opening a CSVhard
- The date that never existedhard
- Financial year from a datehard
- Week number of 1 January 2027hard
- First day of the month from any datehard
- Working days with a Friday–Saturday weekendhard
- Monthly total from a date columnhard
- 7-day average over missing dayshard
- March total misses the last dayhard
- SUM(DISTINCT) gives a low totalhard
- Customers who bought every item in a sethard
- Month-1 retention for a cohorthard
- Subquery returns more than one rowhard
- NULL score ranked firsthard
- Every share shows 0hard
- LAG default vs COALESCEhard
- Forward-filling missing priceshard
- Streaks broken by repeat loginshard
- Runs of the same machine statushard
- Merging overlapping bookingshard
- Largest fall from a peakhard
- PRECEDING with a descending orderhard
- Running totals in an incremental modelhard
- Spark window with no partitionhard
- Average of everyone else in the teamhard
- GROUPS frame with tied dateshard
- Percent of total with LIMIT 10hard
- End dates for history rowshard
- Equal scores in different quartileshard
- A slow filter on a window viewhard
- Order count of zero after a LEFT JOINhard
- Users with a 3-day streakhard
- One partition takes all the timehard
- Five windows, five sortshard
- Products within ₹500 of each pricehard
- What EXCLUDE TIES removeshard
- Median per department in PostgreSQLhard
- Last known value with IGNORE NULLShard
- Ties that are not quite tieshard
- Purpose of a primary keyeasy
- Row count of a LEFT JOINeasy
- Filtering with = NULLeasy
- COUNT(*) vs COUNT(column)easy
- Filtering groups with HAVINGeasy
- Adding a number to NULLeasy
- Orders pointing to missing customerseasy
- First check after a migrationeasy
- Removing duplicate order idseasy
- Grouping sales by montheasy
- avg and count with a null valueeasy
- Joining with a small lookup tablemedium
- Upserting into a target tablemedium
- Keeping the latest row per keymedium
- RANK and DENSE_RANK with tiesmedium
- NOT IN with a NULL in the listmedium
- Day-over-day change with LAGmedium
- WHERE filter after a LEFT JOINmedium
- Counting orders for every customermedium
- Table state after a MERGEmedium
- Revenue doubled after a joinmedium
- Employees above their team averagemedium
- Keeping SQL in separate filesmedium
- Selecting current rows from SCD2medium
- Joining facts to the right SCD2 versionmedium
- Keeping one row per ordermedium
- Row counts match but money does notmedium
- Keeping the latest row per customermedium
- Applying a batch of changesmedium
- Joining two topics in Kafka Streamsmedium
- Joining with a small reference tablemedium
- Matching orders with paymentsmedium
- Subtotals with rollupmedium
- Same timestamp, different hourmedium
- Rows missing after a != filtermedium
- Running total with tied dateshard
- LAST_VALUE returns the current rowhard
- Longest login streakhard
- FULL OUTER JOIN row counthard
- GROUP BY with NULL keyshard
- Recursive CTE stopping pointhard
- Double counting in an SCD2 joinhard
- Distinct users on billions of rowshard
- Which day does an event belong tohard
- Date key for a late-night Dubai orderhard
- MERGE fails on duplicate source rowshard
- Revenue inflated by repeated eventshard
- GST totals off by a few rupeeshard
- No FX rate for Saturday ordershard
- Bank and app never agree on a dayhard
- Duplicates that slip past a stream dedupehard
- Revenue tripled after a joinhard
- Monthly users from daily usershard
- Enriching events with a changing tablehard
- Verifying data with SQLmedium
- Finding duplicate records with SQLmedium
- Migration check returns nothinghard
- Applying filters on mobilemedium
- Filtering by several attributesmedium
- Filters that lead to nothingmedium
- A DAU query bugmedium
- Joining for retained usersmedium
- First purchase per usermedium
- Order of steps in SQLmedium
- Counting by local daymedium
- Days between orders with LAGmedium
- A filter that breaks a left joinhard
- Approximate distinct countshard
- Off-by-one in day countshard
- Filtering rows in SQLeasy
- Finding customers with no ordersmedium
- Customers with many ordersmedium
- "2 minutes ago" or a full date?easy
- Writing dates for many countriesmedium
- Writing a deadline with a time zonemedium
- SQL: assigning signup cohortsmedium
- SQL: active last month, not this monthmedium
- NRR from an ARR tablemedium
- SQL: classify MRR changes with LAGhard
- Retention above 100%?hard
- A buggy upcoming-renewals queryhard
- Intercompany balances that do not agreehard
- DSO query returns zeromedium
- YoY growth query mixes companieshard