Interview preparation
SQL Subquery Interview Questions
Subquery patterns interviewers actually ask: second highest, above average, NOT IN vs NOT EXISTS, and derived tables — with practice questions.
The subquery patterns that recur
Scalar subqueries in WHERE for 'second highest' and 'above average'; IN with a derived set for 'customers who did X'; derived tables in FROM for pre-aggregation.
The NULL trap in NOT IN is a favorite interview follow-up: what happens when the subquery returns NULL? The answer — nothing matches — is worth knowing cold.
Practice questions
- easyClasses With At Least 5 Students
- easyCustomers Without Orders
- easyDuplicate Emails
- easySecond Highest Salary
- mediumConsecutive Login Days
- mediumCustomers Who Bought All Products
- mediumDepartments by Average Salary
- mediumExchange Seats
- mediumImmediate Food Delivery
- mediumLongest Login Streak
- mediumNth Highest Salary
- mediumOrders Gap Analysis