SQL Subqueries Practice Problems: 240 Questions with Solutions
240 SQL subqueries practice problems with solutions: IN, EXISTS, correlated subqueries, derived tables and CTEs. Written in MySQL, judged on hidden datasets.
- Problems: 240
- By difficulty: 44 easy · 96 medium · 100 hard
- Dialect: MySQL
Practise SQL subqueries: scalar subqueries, IN and NOT IN, EXISTS and NOT EXISTS, correlated subqueries and derived tables in FROM, plus common table expressions with WITH. Many of these questions can also be answered with a join or a window function; where a problem has a second reference query, its page shows it.
Easy SQL subqueries problems
- Hostel Students Who Never Ordered From the Canteen
- Canteen Staff Whose Supervisor Has Left
- Customers Without a Verified KYC Document
- Savings Accounts Above the Bank-Wide Average Balance
- Catalogue Products Nobody Has Wishlisted
- Courses Nobody Registered For in the Odd Semester
- Menu Items Nobody Has Ordered
- Players Who Never Queued for Ranked
- Players Rated Above the Average MMR
- Employees Without a Reachable Emergency Contact
- Sensors Silent Through January
- Campaigns That Got Clicks but No Conversions
- Drivers Rated Above the Fleet Average
- On-Call Engineers Who Were Not Paged in March
- Leads Never Taken on a Completed Site Visit
- Suppliers With No Purchase Order in 2024
- Active Subscriptions Above the Average MRR
- Posts With No Likes From Anyone but the Author
- Posts With More Likes Than the Platform Average
- Fantasy Teams That Forgot to Pick a Captain
- Movies Longer Than the Average Movie
- Dormant Prepaid Subscribers Since March
- Hotel Rooms Priced Above the Average Tariff
- Airbnb: Hosts With No Active Listing
- Apple: Developer Teams With No Approved App Yet
- Dream11: Depositors Who Never Joined a Contest
- Flipkart: Product Questions Still Waiting for an Answer
- Google: Published Play Apps With No Installs
- Hotstar: Plans With No Active Subscriber
- Hotstar: Watchlist Titles the Profile Never Played
- LinkedIn: Company Pages With No New Followers in May 2025
- Meta: Verified WhatsApp Businesses With No Live Catalog Items
- Microsoft: Licensed Users With No Successful Sign-In
- Myntra: Live Styles With No Approved Catalogue Image
- Myntra: Wishlisted Styles the Shopper Has Not Bought Yet
- Ola: Hypercharger Stations Idle Through a Whole Week
- Paytm: Soundbox Devices That Never Announced a Payment
- PhonePe: QR Stickers That Never Took a Successful Payment
- Razorpay: Open QR Codes That Never Received a Payment
- Spotify: Artists Who Released Nothing in 2024
- Swiggy: Swiggy One Plans With No Order Placed
- Uber: Promo Codes Nobody Has Redeemed
- Walmart: Grocery Pickup Slots Nobody Booked
- Zomato: Gold Members Yet to Use a Single Benefit
Medium SQL subqueries problems
- Costliest Auction Buy of Each Cricket Team
- Share of Quiz Players Who Returned the Next Day
- Students Who Attended Every Fest Workshop
- Second-Best Innings in the College Cup
- Swap Neighbouring Seats in the Exam Hall
- Student With the Most Study Buddies
- Canteen Menu Prices on 15 March
- Crop Cover for Shared Amounts on Unique Plots
- Top Reviewer and Best-Rated Dish of February
- Inoperative Accounts Under the Two-Year Rule
- Resale Listings Marked Up Above Their Event's Average
- Books With the Longest Reservation Queue
- Customers Whose First Order Used a Coupon
- Wishlisted Products That Are Now Cheaper
- Students Scoring Above Their Section's Internal Average
- Backlogs Cleared on a Later Attempt
- Orders Above the Customer's Own Average Basket
- Restaurants Cooking Faster Than Their City Average
- Whale Share of Monthly Store Revenue
- Guild Members Above Their Guild's Average Points
- Patients Readmitted Within 30 Days of Discharge
- Lab Tests Slower Than Their Usual Turnaround
- Diabetic Patients Whose Latest HbA1c Improved
- Salary Hike Percentage at the April 2025 Appraisal
- High Performers Due for a Promotion Review
- Monthly Attrition Rate in 2024
- Machines Due for Preventive Maintenance by Quarter End
- Batches Worse Than Their Product's Defect Rate
- Last-Touch Channel for Each Conversion
- Campaigns Outspending Their Channel's Average
- Latest Tracking Scan for Each Parcel
- Couriers Delivering More Than Their Hub's Average in June
- Agents Carrying More Than Their Team's Average Workload
- Flats Owing More Than Their Wing's Average
- Towers Where Every Unit Cleared March Dues
- Purchase Order Lines Received Short
- Slow-Moving SKUs Still Holding Stock
- Stores Beating Their City's Average in Q1
- Paid Accounts Dormant for Over 30 Days
- Drive-By Commenters Who Never Liked the Post
- Creators Whose Latest Post Underperformed
- Football League Table With Points and Goal Difference
- Auction Buys Above Their Franchise's Average Price
- Titles Licensed in Every Region on Launch Day
- Data Users Above Their Circle's Average
- Loyalty Points Expiring for Inactive Members
- Airbnb: Guests Who Came Back to the Same Host Within a Year
- Airbnb: Rank Experiences by a Bayesian Average Rating
- Airbnb: Hosts Whose Every Active Listing Is Instant Book
- Amazon: Echo Buyers Who Added a Smart Plug Within 60 Days
- Amazon: Prime Day Deals Not Below the 30-Day Low Price
- Apple: Component Batches Below Their Pooled Test Yield
- Dream11: Selection Percentage of Every Player per Match
- Dream11: Saved Teams Carrying Players Left Out of the XI
- Dream11: Head-to-Head Fixtures Still to Play in Private Leagues
- Flipkart: Certified Buyer Reviews and Their Rating per Product
- Google: Click-Through Rate at Every Organic Position
- Hotstar: Advertisers Owed Make-Good Impressions
- Hotstar: Subscribers Who Only Ever Watch Live Sport
- Hotstar: Subscriptions With No Play in Their First Week
- LinkedIn: Connection Count of Every Member
- LinkedIn: Applicants Holding Every Required Skill
- LinkedIn: Members With Exactly the Same Skill Set
- Meta: Ad Set Metrics Unpivoted Into Long Format
- Meta: Facebook Groups Where Every Admin Approved a Post
- Meta: Moderators Overturned More Often Than Their Team
- Microsoft: Xbox Players Who Unlocked Every Achievement in a Title
- Microsoft: Bing Query Abandonment Rate by Market
- Microsoft: Customers Billed for Both Azure and Microsoft 365
- Microsoft: Privileged Azure Role Holders for the Access Review
- Myntra: Styles Marked Down by at Least 40% for EORS Day One
- Myntra: Wishlist-to-Purchase Conversion by Article Type
- Myntra: Styles Most Shoppers Say Run Small
- Ola: Driver-Partners Cleared on All Four Documents
- Ola: Auto, Mini and Prime Ride Mix in Each City
- Paytm: Users Who Paid Electricity in Every Month of Q1 2025
- Paytm: Mobile Numbers That Switched Operator Between Recharges
- PhonePe: Users Whose First Successful Payment Was at a Merchant
- PhonePe: Motor Policy Renewal Rate by Expiry Month
- PhonePe: Users Who Only Send, Only Receive or Do Both in October
- Razorpay: Subscription Cycles Recovered by Retry vs Halted
- Razorpay: UPI Ticket Sizes in ₹1,000 Bands, Empty Bands Included
- Razorpay: MDR Pricing Rows Added, Removed or Changed Between Snapshots
- Spotify: Free Listeners Who Hit the Hourly Skip Cap
- Spotify: Collaborative Playlists Only the Owner Edits
- Spotify: Artists Not Touring Their Top Listening City
- Spotify: Listeners Who Played an Album Front to Back
- Swiggy: Share of Each Partner's Orders Delivered in a Batch
- Swiggy: Instamart SKUs Out of Stock Across a Whole City
- Uber: Airport Queue Position When Each Driver Arrived
- Uber: Rider Referrals That Qualified for the Bonus
- Uber: UberX Share Requests Matched With a Co-Rider
- Walmart: Clearance Items Marked Down Three Times With No Sale
- Walmart: Pickup Slot Fill Rate by Hour of Day
- Zomato: Reviews Far From the Restaurant's Consensus
- Zomato: District Event Sell-Through by Category
Hard SQL subqueries problems
- Longest Run of Consecutive Missed Loan Instalments
- UPI App New-User Retention in the Following Month
- Reservation Holders to Notify After Today's Returns
- Donor Retention by First-Gift Year
- Monthly Buyer Cohort Retention
- The Redemption That Exhausted Each Coupon Budget
- Day Each Branch Crossed 50% Placement
- Next-Month Retention of First-Order Cohorts
- Food App Checkout Funnel, Step by Step
- Top Two Restaurants per Cuisine by Repeat-Customer Rate
- Battle Pass Race to Tier 30, Season by Season
- Peak Concurrent Game Sessions per Server Region
- Total Recruits Down Each Player's Referral Tree
- OPD New-Patient Retention by Monthly Cohort
- Daily Admissions With Quiet Days and a Running Total
- Org Chart Depth and Business Head of Every Employee
- Service-Due Day in Each Maintenance Cycle
- Click to Sign-up to Purchase Funnel per Campaign
- Median Daily Spend of Each Channel
- Daily Sorting-Hub Backlog Including Days With None
- Gaps in the On-Call Rota
- Repeat Contact Rate by First-Ticket Month
- Six-Month Renter Retention by Move-In Cohort
- Daily Stock Carried Forward From the Last Count
- Month-End MRR From Subscription Periods
- Friend Suggestions From Two or More Mutual Friends
- Reshare Cascades: Size, Depth and Unique Resharers
- Net Run Rate of Every Team in the T20 League
- The Over in Which Each T20 Innings Passed 100 Runs
- Orange Cap Leader After Every Match Day
- Longest Daily Listening Streak per Listener
- Next-Month Viewing Retention of Streaming Sign-Up Cohorts
- Median Session Length by Device
- Free-Trial Conversion and Second-Month Funnel
- Prepaid Recharge Next-Month Retention by Cohort
- Repeat-Guest Retention Within 90 Days by Cohort
- Airbnb: Reconcile Host Payouts Against Earnings
- Amazon: Five-Star Review Bursts From Brand-New Accounts
- Amazon: Suggested Subscribe & Save Cadence From Reorder Gaps
- Amazon: Packing Station Backlog Carried Hour to Hour
- Apple: Leaf Parts Needed for Each Mac Build Order
- Apple: Subscription Billing Lapses Recovered in the Grace Period
- Apple: In-App Revenue at the Price in Effect on Each Day
- Apple: Apple Pay Rolling Seven-Day Fraud Rate
- Dream11: Withdrawals Right After a Deposit With No Play Between
- Dream11: Second-Paid-Contest Activation Rate by Signup Month
- Flipkart: SuperCoins Left in Each Earn Batch After FIFO Burns
- Flipkart: Big Billion Days GMV by Sale Day Against Last Year
- Flipkart: Sale-Acquired Buyers Who Came Back for the Next Sale
- Flipkart: Unscanned Ekart AWB Numbers as Ranges per Hub
- Flipkart: First Day a Seller Logged Three Returns in Seven Days
- Google: YouTube Channels Eligible for the Partner Programme
- Google: Longest YouTube Autoplay Chain in Each Session
- Google: Search Experiment Lift Without Contaminated Users
- Hotstar: Viewers Lost During Each Rain Delay
- Hotstar: Subscribers Covered on Every Playoff Match Day
- LinkedIn: Mutual Connections Behind Pending Invitations
- LinkedIn: Followers Across Each Company's Affiliated Pages
- LinkedIn: First- and Second-Degree Network Size
- LinkedIn: Boomerang Hires in Members' Work History
- Meta: WhatsApp Business Conversation Windows
- Meta: Growth Accounting of Monthly Active Users
- Meta: Trending Reels Tags Split Out of Comma-Separated Lists
- Meta: Instagram Reels Shopping Funnel, Steps in Order
- Meta: Accounts Linked to Banned Accounts Through Shared Devices
- Microsoft: OneDrive Files Whose Full Path Is Too Long to Sync
- Microsoft: Management Groups Whose Rolled-Up Azure Spend Tops Budget
- Microsoft: Azure Prepayment Balance and Overage Month by Month
- Microsoft: Xbox Hunters With the Most Rare Achievements
- Myntra: EORS First-Time Buyers Who Ordered Again Within 90 Days
- Myntra: Each Brand's Three Most-Wishlisted Styles in One Row
- Myntra: Sizes Over-Represented in Size Returns per Article Type
- Ola: Scooters Behind Their Model's Newest Firmware
- Ola: Scooters Covered by a Care Plan on Each Month End
- Ola: Peak Simultaneous Charging Sessions at Each Station
- Ola: Service Tickets Breaching the 3-Working-Day SLA
- Paytm Money: SIP Investor Retention Three Months Later by Cohort
- Paytm: Daily Seats Sold for Every Day of a Movie's Run
- Paytm: Spending Before and After Cashback for Each Campaign
- PhonePe: Users Paying Three New Payees Within One Hour
- Razorpay: Payments Settled After Their T+N Working Day
- Razorpay: Merchants Whose Live Methods Differ From Their Request
- Razorpay: Orders Rescued by Switching Payment Method
- Razorpay: Queued Payouts Rejected for Insufficient Balance
- Razorpay: Subscription Billing Cycles With No Charge Attempt
- Spotify: Podcast Episode-to-Episode Listener Retention
- Spotify: Family Plans That Ever Had Over Six Members at Once
- Spotify: Playlist Pairs Sharing Half Their Available Tracks
- Swiggy: GMV Report With City Subtotals and a Grand Total
- Swiggy: Units Sold per Item From Instamart Combo Codes
- Uber: Evening Hours Where Requests Outran Online Drivers
- Uber: Trip Event Logs That Break the State Machine
- Uber: Which Promo Gets Credit for a Rider's First Trip
- Walmart: Department Pairs Bought Together More Than by Chance
- Walmart: Median Minutes From Shelf Gap to Refill by Department
- Walmart: Assigning Pallets to Trailers Under a Weight Limit
- Zomato: Live Menu Rebuilt From the Latest Approved Edits
- Zomato: Cuisine Gaps in Each Locality Worth Recruiting For
- Zomato: Restaurant Partner Anniversaries Falling in November
- Zomato: Orders Placed While the Restaurant Was Closed