The WHERE clause filters rows in a table to return only those that meet a specified condition.
Click to reveal answer
beginner
How does the AND operator work in a WHERE clause?
The AND operator combines two or more conditions and returns rows only if all conditions are true.
Click to reveal answer
beginner
Write a simple SQL query using WHERE with AND to find employees older than 30 and in the 'Sales' department.
SELECT * FROM employees WHERE age > 30 AND department = 'Sales';
Click to reveal answer
intermediate
Can the AND operator be used with more than two conditions in a WHERE clause?
Yes, you can combine multiple conditions with AND. All must be true for a row to be included.
Click to reveal answer
beginner
What happens if one condition in a WHERE clause with AND is false?
The entire WHERE condition is false, so the row is excluded from the results.
Click to reveal answer
What does the AND operator do in a SQL WHERE clause?
AReturns rows where any condition is true
BReturns all rows regardless of conditions
CReturns rows where no condition is true
DReturns rows where all conditions are true
✗ Incorrect
The AND operator requires all conditions to be true for a row to be included.
Which SQL query correctly uses WHERE with AND to find products priced above 100 and in stock?
ASELECT * FROM products WHERE price > 100 AND stock > 0;
BSELECT * FROM products WHERE price > 100 OR stock > 0;
CSELECT * FROM products WHERE price > 100;
DSELECT * FROM products WHERE stock > 0;
✗ Incorrect
Only option A uses AND to require both conditions: price above 100 and stock available.
If a row meets the first condition but not the second in a WHERE clause with AND, will it be included?
AYes, because one condition is true
BNo, because all conditions must be true
CYes, if the second condition is false
DNo, because <code>AND</code> ignores conditions
✗ Incorrect
With AND, all conditions must be true for the row to be included.
Can you use more than two conditions combined with AND in a WHERE clause?
AOnly three conditions are allowed
BNo, only two conditions are allowed
CYes, any number of conditions can be combined
DOnly if combined with <code>OR</code>
✗ Incorrect
SQL allows combining many conditions with AND in a WHERE clause.
What is the result of this query? SELECT * FROM users WHERE age > 18 AND city = 'Paris';
AUsers older than 18 who live in Paris
BUsers older than 18 or who live in Paris
CUsers younger than 18 who live in Paris
DAll users regardless of age or city
✗ Incorrect
The query returns users who satisfy both conditions: age over 18 and city equals Paris.
Explain how the WHERE clause with the AND operator filters data in SQL.
Think about how you pick fruits that are both ripe and red.
You got /4 concepts.
Write an example SQL query using WHERE with AND to find records matching two conditions.
Try to find employees who work in 'HR' and have a salary above 50000.
You got /4 concepts.
Practice
(1/5)
1. What does the WHERE clause with the AND operator do in an SQL query?
easy
A. Filters rows that meet any one of the conditions
B. Joins two tables together
C. Filters rows that meet all specified conditions
D. Sorts the result set in ascending order
Solution
Step 1: Understand the WHERE clause
The WHERE clause filters rows based on conditions given in the query.
Step 2: Understand the AND operator
The AND operator requires all conditions to be true for a row to be included.
Final Answer:
Filters rows that meet all specified conditions -> Option C
Quick Check:
WHERE + AND = all conditions true [OK]
Hint: AND means all conditions must be true together [OK]
Common Mistakes:
Thinking AND means any condition can be true
Confusing WHERE with JOIN
Assuming AND sorts data
2. Which of the following is the correct syntax to select rows where age is greater than 18 AND city is 'New York'?
easy
A. SELECT * FROM users WHERE age > 18 AND city = 'New York';
B. SELECT * FROM users WHERE age > 18, city = 'New York';
C. SELECT * FROM users WHERE age > 18 OR city = 'New York';
D. SELECT * FROM users WHERE age > 18 AND city == 'New York';
Solution
Step 1: Check the operator between conditions
The question asks for AND, so the operator must be AND, not OR or comma.
Step 2: Check the comparison operators
Use single equals (=) for comparison in SQL, not double equals (==).
Final Answer:
SELECT * FROM users WHERE age > 18 AND city = 'New York'; -> Option A
Quick Check:
AND + = correct syntax [OK]
Hint: Use AND and single = for conditions in WHERE [OK]
Common Mistakes:
Using OR instead of AND
Using comma instead of AND
Using == instead of = for comparison
3. Given the table employees with columns name, department, and salary, what will this query return?
SELECT name FROM employees WHERE department = 'Sales' AND salary > 50000;
medium
A. Names of employees in Sales with salary over 50000
B. Names of employees in Sales or salary over 50000
C. All employees with salary over 50000
D. Syntax error due to missing OR
Solution
Step 1: Analyze the WHERE clause conditions
The query filters rows where department equals 'Sales' AND salary is greater than 50000.
Step 2: Understand the AND effect
Only employees meeting both conditions will be selected, so names returned are from Sales with salary above 50000.
Final Answer:
Names of employees in Sales with salary over 50000 -> Option A
Quick Check:
AND filters both conditions true [OK]
Hint: AND means both conditions must be true to select rows [OK]
Common Mistakes:
Thinking OR is used instead of AND
Assuming it returns all employees with salary > 50000
Believing syntax error occurs without OR
4. Identify the error in this SQL query:
SELECT * FROM products WHERE price > 100 AND category 'Electronics';
medium
A. AND should be OR
B. Missing comparison operator (=) before 'Electronics'
C. price > 100 is invalid syntax
D. Missing FROM keyword
Solution
Step 1: Check the WHERE clause syntax
The condition after AND is missing a comparison operator before 'Electronics'. It should be category = 'Electronics'.
Step 2: Verify other parts
price > 100 is correct, AND is valid, and FROM is present.
Final Answer:
Missing comparison operator (=) before 'Electronics' -> Option B
Quick Check:
Comparison operator needed before value [OK]
Hint: Each condition needs a comparison operator like = [OK]
Common Mistakes:
Omitting = in conditions
Replacing AND with OR incorrectly
Ignoring syntax errors in WHERE clause
5. You have a table orders with columns order_id, customer_id, status, and total. Write a query to find all orders with status 'shipped' AND total greater than 100, but exclude orders where customer_id is NULL. Which query is correct?
hard
A. SELECT * FROM orders WHERE status = 'shipped' AND total > 100 AND customer_id != NULL;
B. SELECT * FROM orders WHERE status = 'shipped' OR total > 100 AND customer_id IS NOT NULL;
C. SELECT * FROM orders WHERE status = 'shipped' AND total > 100 OR customer_id IS NOT NULL;
D. SELECT * FROM orders WHERE status = 'shipped' AND total > 100 AND customer_id IS NOT NULL;
Solution
Step 1: Combine conditions with AND
We want orders where status is 'shipped' AND total is greater than 100 AND customer_id is not NULL.
Step 2: Use correct syntax for NULL check
In SQL, to check for NULL, use IS NOT NULL, not != NULL.
Final Answer:
SELECT * FROM orders WHERE status = 'shipped' AND total > 100 AND customer_id IS NOT NULL; -> Option D
Quick Check:
Use AND and IS NOT NULL for correct filtering [OK]
Hint: Use IS NOT NULL to exclude NULLs with AND [OK]
Common Mistakes:
Using OR instead of AND
Using != NULL instead of IS NOT NULL
Mixing AND and OR without parentheses
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.