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.

💡 Basic syntax: WHERE column = 'value' — Always use single quotes around text values. The text must match exactly, including spelling and spacing.
Problem 1 Find all employees who work in the Sales department. Table: employees
Columns: employee_id, first_name, last_name, department, job_title, salary
Show solution ↓

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.

Problem 2 Show all columns for orders that were shipped via Standard delivery. Table: orders
Columns: order_id, customer_id, order_date, total_usd, status, shipping_method
Show solution ↓

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.

Problem 3 Find all properties listed as Apartments. Show all columns. Table: rental_listings
Columns: listing_id, property_type, city, bedrooms, price_per_night, rating
Show solution ↓

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'.

Problem 4 Show the first name, last name, and job title of all employees whose job title is Manager. Table: employees
Columns: employee_id, first_name, last_name, department, job_title, salary
Show solution ↓

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.

💡 Comparison operators: = (equal), != (not equal), > (greater than), >= (greater than or equal), < (less than), <= (less than or equal). Never use quotes around numbers.
Problem 5 Find all orders with a total value greater than $100. Table: orders
Columns: order_id, customer_id, order_date, total_usd, status, shipping_method
Show solution ↓

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.

Problem 6 Show all columns for rental listings priced at $150 per night or less. Table: rental_listings
Columns: listing_id, property_type, city, bedrooms, price_per_night, rating
Show solution ↓

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.

Problem 7 Find all employees with a salary of $60,000 or more. Show all columns. Table: employees
Columns: employee_id, first_name, last_name, department, job_title, salary
Show solution ↓

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.

Problem 8 Show the listing ID, city, and rating for all rental listings with a rating above 4.5. Table: rental_listings
Columns: listing_id, property_type, city, bedrooms, price_per_night, rating
Show solution ↓

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.

💡 Clause order matters: WHERE must always come before ORDER BY. Putting them in the wrong order will cause an error.
Problem 9 Show all Sales department employees sorted from highest to lowest salary. Return all columns. Table: employees
Columns: employee_id, first_name, last_name, department, job_title, salary
Show solution ↓

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.

Problem 10 Show all orders over $50, sorted from most recent to oldest. Return all columns. Table: orders
Columns: order_id, customer_id, order_date, total_usd, status, shipping_method
Show solution ↓

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.

Problem 11 Show the city, price per night, and rating for all Apartment listings, sorted from cheapest to most expensive. Table: rental_listings
Columns: listing_id, property_type, city, bedrooms, price_per_night, rating
Show solution ↓

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.

💡 AND vs OR: WHERE a = 1 AND b = 2 returns rows where both conditions are true. WHERE a = 1 OR b = 2 returns rows where either condition is true. AND is more restrictive — it typically returns fewer rows than OR.
Problem 12 Find all employees in the Sales department who earn more than $50,000. Table: employees
Columns: employee_id, first_name, last_name, department, job_title, salary
Show solution ↓

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.

Problem 13 Show all rental listings that are either in Paris or in Rome. Return all columns. Table: rental_listings
Columns: listing_id, property_type, city, bedrooms, price_per_night, rating
Show solution ↓

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.

Problem 14 Find all orders that are Pending AND were placed for more than $75. Return all columns. Table: orders
Columns: order_id, customer_id, order_date, total_usd, status, shipping_method
Show solution ↓

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.

Problem 15 Show all employees who work in either the Marketing or Finance department AND earn $70,000 or more. Return the first name, last name, department, and salary. Table: employees
Columns: employee_id, first_name, last_name, department, job_title, salary
Show solution ↓

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.