Scalar subquery for comparison

Easy
3 views 23 Jan 2026
Find employees whose salary is above the company average salary....

IN subquery filter

Easy
2 views 23 Jan 2026
List customers who have placed at least one order....

EXISTS for faster membership

Easy
2 views 23 Jan 2026
Find products that have at least one order item....

Subquery in FROM (derived table)

Easy
2 views 23 Jan 2026
Get department-wise average salary, then list departments where avg salary > 50000....

Correlated subquery for per-row condition

Easy
2 views 23 Jan 2026
List employees who earn more than the average salary of their own department....

Find latest order per customer using subquery

Medium
4 views 23 Jan 2026
Return orders that are the latest order for each customer....

Second highest salary using subquery

Medium
3 views 23 Jan 2026
Return the second highest distinct salary from Employees....

Find customers with more than N orders

Medium
3 views 23 Jan 2026
Write a query using subquery that returns customers who placed more than 3 orders....

NOT IN pitfall with nulls (safe version)

Medium
3 views 23 Jan 2026
Find customers who did not place any order. Use NOT EXISTS (safer than NOT IN)....

Update with correlated subquery

Medium
3 views 23 Jan 2026
Update Employees set salary to department average salary for employees who have salary NULL....

Find products priced above category average

Hard
8 views 23 Jan 2026
Return products where price is greater than average price of their category....

Detect customers who always pay late

Hard
3 views 23 Jan 2026
Payments(order_id, due_date, paid_at). Find customers where for every payment, paid_at > due_date....

Correlated delete using subquery

Hard
2 views 23 Jan 2026
Delete Products that were created more than 365 days ago and never appeared in OrderItems. Use NOT EXISTS to avoid NULL issues....

Subquery for top category by revenue

Hard
2 views 23 Jan 2026
Find the product category with the highest revenue. Revenue = SUM(qty * price) from OrderItems joined with Products....

Customers whose every order is fully paid

Hard
2 views 23 Jan 2026
Return customers for which there is no order with unpaid balance. Unpaid means Orders.total_amount > sum(Payments.amount)....