15 SQL WHERE Clause Practice Problems with Solutions
The WHERE clause is one of the most useful tools in SQL — it lets you filter rows so you only see the data you actually need. This practice set covers 15 beginner-friendly WHERE clause problems progressing from basic text filtering through numeric comparisons, combining WHERE with ORDER BY, and filtering with multiple conditions using AND and OR. Click any problem to reveal the solution.
Part 1 — Text Filtering (Problems 1–4)
The most common use of WHERE is filtering rows based on a text value. Use the = operator and wrap the value in single quotes.
Solution
SELECT * FROM employees WHERE department = 'Sales';
Explanation
WHERE department = 'Sales' tells the database to only return rows where the department column equals 'Sales' exactly. Every other row is filtered out. Notice the text value is wrapped in single quotes — this is always required for text comparisons in SQL.
Solution
SELECT * FROM orders WHERE shipping_method = 'Standard';
Explanation
WHERE shipping_method = 'Standard' filters the results to only rows where the shipping method is Standard. Orders shipped via Express or any other method are excluded. SELECT * returns all columns for the matching rows.
Solution
SELECT * FROM rental_listings WHERE property_type = 'Apartment';
Explanation
WHERE property_type = 'Apartment' filters to only Apartment listings. All other property types like House or Studio are excluded. The text value must match exactly — 'apartment' in lowercase would not match if the data stores it as 'Apartment'.
Solution
SELECT first_name, last_name, job_title FROM employees WHERE job_title = 'Manager';
Explanation
WHERE job_title = 'Manager' filters to only Manager rows. The SELECT clause then limits which columns are shown — just first_name, last_name, and job_title. Notice you can filter on a column without including it in SELECT, but here job_title is included in both.
Part 2 — Numeric Comparisons (Problems 5–8)
WHERE works just as well with numbers. You can use comparison operators to filter rows based on numeric values — no quotes needed around numbers.
Solution
SELECT * FROM orders WHERE total_usd > 100;
Explanation
WHERE total_usd > 100 keeps only rows where the order total exceeds $100. Orders worth exactly $100 are excluded because > means strictly greater than. If you wanted to include $100 orders, you'd use >= 100 instead. Notice there are no quotes around the number.
Solution
SELECT * FROM rental_listings WHERE price_per_night <= 150;
Explanation
WHERE price_per_night <= 150 keeps rows where the nightly price is $150 or below. The <= operator means "less than or equal to" so listings priced at exactly $150 are included. Listings priced above $150 are filtered out.
Solution
SELECT * FROM employees WHERE salary >= 60000;
Explanation
WHERE salary >= 60000 keeps employees earning $60,000 or more. The >= operator means "greater than or equal to" so employees earning exactly $60,000 are included. Employees earning less than $60,000 are excluded.
Solution
SELECT listing_id, city, rating FROM rental_listings WHERE rating > 4.5;
Explanation
WHERE rating > 4.5 filters to only highly rated listings. The SELECT clause limits the output to just three columns — listing_id, city, and rating. You can combine selective column choosing with WHERE filtering in the same query.
Part 3 — WHERE with ORDER BY (Problems 9–11)
WHERE and ORDER BY are frequently used together. WHERE filters the rows first, then ORDER BY sorts the remaining results. The clause order always goes: SELECT → FROM → WHERE → ORDER BY.
Solution
SELECT * FROM employees WHERE department = 'Sales' ORDER BY salary DESC;
Explanation
WHERE department = 'Sales' filters to only Sales employees first. ORDER BY salary DESC then sorts those filtered results from highest to lowest salary. The filtering happens before the sorting — SQL always processes WHERE before ORDER BY.
Solution
SELECT * FROM orders WHERE total_usd > 50 ORDER BY order_date DESC;
Explanation
WHERE total_usd > 50 filters to orders over $50. ORDER BY order_date DESC then sorts those orders so the most recent appear first. This is a common pattern — filter to relevant rows, then sort them in a useful order.
Solution
SELECT city, price_per_night, rating FROM rental_listings WHERE property_type = 'Apartment' ORDER BY price_per_night;
Explanation
WHERE property_type = 'Apartment' filters to only Apartment listings. ORDER BY price_per_night sorts those results from cheapest to most expensive — no DESC needed since ascending is the default. The SELECT clause limits the output to just the three most relevant columns.
Part 4 — Multiple Conditions with AND / OR (Problems 12–15)
You can combine multiple conditions in a single WHERE clause using AND and OR. AND means both conditions must be true. OR means at least one condition must be true.
Solution
SELECT * FROM employees WHERE department = 'Sales' AND salary > 50000;
Explanation
AND combines two conditions — both must be true for a row to be included. This query only returns employees who are in Sales AND earn more than $50,000. A Sales employee earning $40,000 would be excluded. An Engineering employee earning $80,000 would also be excluded.
Solution
SELECT * FROM rental_listings WHERE city = 'Paris' OR city = 'Rome';
Explanation
OR means at least one condition must be true. This query returns listings where the city is Paris OR the city is Rome — so listings from either city are included. A listing in London would be excluded since it doesn't match either condition.
Solution
SELECT * FROM orders WHERE status = 'Pending' AND total_usd > 75;
Explanation
Both conditions must be true for a row to be returned. A Pending order worth $60 is excluded because it doesn't meet the price condition. A Delivered order worth $100 is excluded because it doesn't meet the status condition. Only Pending orders over $75 are returned.
Solution
SELECT first_name, last_name, department, salary FROM employees WHERE (department = 'Marketing' OR department = 'Finance') AND salary >= 70000;
Explanation
This query mixes OR and AND. The parentheses around the OR conditions are important — they ensure the department filter is evaluated first as a group, and then the salary condition is applied to that result. Without parentheses, SQL might evaluate the AND before the OR and return unexpected results. When mixing AND and OR, always use parentheses to make your intentions clear.
Ready to practice WHERE clause queries interactively? Write real queries and get instant feedback in the SQL Drills exercise tool.
Practice WHERE Interactively →Want more practice? Try the multiple conditions exercises to go deeper with AND and OR, or head back to the SQL Drills Learn hub for more practice sets and guides.