SQL Basics: Filtering, Sorting and Limits
Every SQL interview starts here. These questions cover choosing rows with WHERE, combining conditions, handling NULLs, sorting with ORDER BY and keeping only the rows you need with LIMIT and DISTINCT.
20 questions · 9 Easy · 8 Medium · 3 Hard · about 2.8 hours · MySQL & PostgreSQL
What you'll practise
- WHERE and AND / OR conditions
- IN, BETWEEN and range filters
- NULL handling
- ORDER BY with tie-breakers
- LIMIT and top-N queries
- DISTINCT
Learn the concepts first
Questions in this plan
Top Paid Engineers
Show the name and salary of employees in 'Engineering' who earn more than 70000, highest first, top 3.
Multilingual Language Speakers
Identify users who speak at least two distinct target languages ('English', 'Spanish', 'German') from skill profile records.
Users With Zero Searches
Find registered account profiles that have never submitted a search query using an outer join.
Play Store: Top Rated App Categories
Find categories with at least 3 apps rated 4.0 or higher, returning the category, app count, and average rating rounded to 2 decimals.
Google Maps: High-Impact Local Guides
Find verified reviewers who submitted at least 2 photo reviews in San Francisco or Mountain View.
Google Drive: External Sensitive File Shares
Audit sensitive files shared with non-Google email addresses to identify potential data exposure risks.
Google Cloud: Underutilized Virtual Machines
Detect running compute instances exhibiting low CPU and memory utilization to optimize infrastructure costs.
YouTube: Top Video Engagement Rate
Evaluate recently published high-traffic videos to surface those with exceptional like-to-view ratios.
Cities With Most Loyal Customers
Group users by metropolitan territory and rank locations by repeat checkout count over 90 days.
Rank Salaries Within Department
Assign dense rank values to employee compensations per department without skipping ranks for tied salaries.
Google Workspace: Storage Quota Alerts
Calculate total Drive storage per organization and return those exceeding their quota, showing total used and excess GB.
Google Play: High-Value Repeat Spenders
Identify key monetization users in target regions who executed 3+ in-app purchases totaling over $100.
Second Highest Salary
Find the second highest distinct salary from the Employee table without duplicate values.
Nth Highest Salary
Write a dynamic MySQL stored procedure or subquery to retrieve the Nth distinct salary ranking.
Amazon: Marketplace Seller Return Rate
Identify marketplace merchants with at least 5 fulfilled orders whose customer return rate exceeds 10%.
Amazon: First Order Details
Retrieve each customer's very first order, resolving date ties by selecting the lowest order_id.
Amazon: Best-Selling Products per Category
Identify the top-selling product in each retail category by total units sold, returning all tied leaders using DENSE_RANK.
Amazon: Frequently Bought Together
Identify product pairs purchased together in the same order at least 3 times without duplicate pairs or reflexive matches.
Monthly Net Revenue by Customer
Net payments, refunds and chargebacks into the month each money movement happened.
Three-Month Salary Window
Each employee's rolling three-month salary total, excluding their most recent month.