Start simple. Build confidence. These 10 SELECT challenges go from beginner to intermediate. Each one tests a different skill. Try to write the query before looking at the solution.
Find all customers who live in Mumbai. Show their full name and signup date.
SELECT first_name, last_name, signup_date
FROM customers
WHERE city = 'Mumbai'
ORDER BY signup_date;List all products priced under Rs 1000. Show name, category, and price. Sort cheapest first.
SELECT product_name, category, price
FROM products
WHERE price < 1000
ORDER BY price ASC;Find all completed orders placed in June 2024. Show order_id, order_date, and total_amount.
SELECT order_id, order_date, total_amount
FROM orders
WHERE status = 'completed'
AND order_date BETWEEN '2024-06-01' AND '2024-06-30'
ORDER BY order_date;Show the 5 most expensive products. Include name, category, and price.
SELECT product_name, category, price
FROM products
ORDER BY price DESC
LIMIT 5;Find customers who signed up between January 1 and March 31, 2024.
SELECT customer_id, first_name, last_name, city, signup_date
FROM customers
WHERE signup_date BETWEEN '2024-01-01' AND '2024-03-31'
ORDER BY signup_date;List all unique cities where customers are located. Sort alphabetically.
SELECT DISTINCT city
FROM customers
ORDER BY city;Find all orders where total_amount exceeds Rs 50,000. Show order_id, customer_id, total_amount, and status.
SELECT order_id, customer_id, total_amount, status
FROM orders
WHERE total_amount > 50000
ORDER BY total_amount DESC;Find all products whose name contains "Pro" or "Premium".
SELECT product_id, product_name, category, price
FROM products
WHERE product_name LIKE '%Pro%'
OR product_name LIKE '%Premium%';Find all orders that are NOT completed. Show order_id, status, and total_amount. Use IN operator.
SELECT order_id, status, total_amount
FROM orders
WHERE status IN ('pending', 'cancelled', 'returned')
ORDER BY status, total_amount DESC;Categorize products by price range. Under Rs 1000 = "Budget", Rs 1000 to Rs 10000 = "Mid-Range", above Rs 10000 = "Premium".
SELECT product_name, price,
CASE
WHEN price < 1000 THEN 'Budget'
WHEN price BETWEEN 1000 AND 10000 THEN 'Mid-Range'
ELSE 'Premium'
END AS price_category
FROM products
ORDER BY price;Q: What is the difference between WHERE and HAVING?
A: WHERE filters rows BEFORE grouping. HAVING filters groups AFTER aggregation. You cannot use aggregate functions (COUNT, SUM, AVG) in WHERE. Example: WHERE price > 100 filters individual rows. HAVING COUNT(*) > 5 filters groups that have more than 5 rows. A common mistake in interviews is trying to use HAVING without GROUP BY — it technically works on the entire result set as one group, but it is almost always a bug.
BETWEEN is inclusive on both ends. "BETWEEN 1 AND 10" includes 1 and 10. For dates, be careful — "BETWEEN 2024-06-01 AND 2024-06-30" will miss timestamps after midnight on June 30. Use "< 2024-07-01" for datetime columns.
Key Point: Master the basics: WHERE, LIKE, IN, BETWEEN, DISTINCT, CASE, ORDER BY, and LIMIT. These appear in every SQL interview.