The WHERE clause filters rows in a table based on a condition, so only rows that meet the condition are returned.
Click to reveal answer
beginner
Name four common comparison operators used in the WHERE clause.
Common comparison operators are: = (equal), < (less than), > (greater than), <= (less than or equal), >= (greater than or equal), and <> or != (not equal).
Click to reveal answer
beginner
How would you write a query to find all employees with a salary greater than 50000?
Use: SELECT * FROM employees WHERE salary > 50000; This returns all employees earning more than 50000.
Click to reveal answer
beginner
What happens if you omit the WHERE clause in a SELECT statement?
The query returns all rows from the table without filtering, showing every record.
Click to reveal answer
intermediate
Can you use multiple comparison operators together in a WHERE clause?
Yes, by combining conditions with AND or OR. For example: WHERE age > 20 AND salary < 70000.
Click to reveal answer
Which operator checks if two values are equal in a WHERE clause?
A=
B<
C>
D!=
✗ Incorrect
The '=' operator tests if two values are equal.
What does the operator '<>' mean in SQL?
ALess than
BGreater than
CNot equal
DEqual
✗ Incorrect
The '<>' operator means 'not equal' in SQL.
How do you find rows where a column value is less than or equal to 100?
AWHERE column <= 100
BWHERE column >= 100
CWHERE column = 100
DWHERE column > 100
✗ Incorrect
The '<=' operator means 'less than or equal to'.
Which keyword combines multiple conditions in a WHERE clause so both must be true?
AOR
BAND
CNOT
DBETWEEN
✗ Incorrect
The 'AND' keyword requires both conditions to be true.
What will this query return? SELECT * FROM products WHERE price > 50;
AProducts with price exactly 50
BAll products
CProducts with price less than 50
DProducts with price greater than 50
✗ Incorrect
The condition 'price > 50' filters products costing more than 50.
Explain how the WHERE clause works with comparison operators in SQL.
Think about how you pick items from a list based on a rule.
You got /3 concepts.
Describe how to combine multiple conditions in a WHERE clause using comparison operators.
Imagine choosing fruits that are both red AND sweet.
You got /3 concepts.
Practice
(1/5)
1. What does the WHERE clause do in an SQL query?
easy
A. Filters rows based on a condition
B. Sorts rows in ascending order
C. Joins two tables together
D. Creates a new table
Solution
Step 1: Understand the purpose of WHERE
The WHERE clause is used to select only those rows that meet a specific condition.
Step 2: Compare with other SQL clauses
Sorting is done by ORDER BY, joining by JOIN, and creating tables by CREATE TABLE, so these are not correct.
Final Answer:
Filters rows based on a condition -> Option A
Quick Check:
WHERE filters rows = A [OK]
Hint: WHERE filters rows; ORDER BY sorts rows [OK]
Common Mistakes:
Confusing WHERE with ORDER BY
Thinking WHERE creates or joins tables
Assuming WHERE changes table structure
2. Which of the following is the correct syntax to select rows where the column age is greater than 30?
easy
A. SELECT * FROM table WHERE age >= 30;
B. SELECT * FROM table WHERE age > 30;
C. SELECT * FROM table WHERE age >> 30;
D. SELECT * FROM table WHERE age = > 30;
Solution
Step 1: Identify correct comparison operator
The operator for 'greater than' is >, so age > 30 is correct.
Step 2: Check syntax correctness
The option with SELECT * FROM table WHERE age = > 30; has invalid operator '= >', the one with '>>' uses bitwise shift, and the one with '>=' means 'greater or equal to', not strictly greater.
Final Answer:
SELECT * FROM table WHERE age > 30; -> Option B
Quick Check:
Use > for greater than, not >= or >> [OK]
Hint: Use > for greater than, >= for greater or equal [OK]
Common Mistakes:
Using '= >' instead of '>'
Confusing '>' with '>>'
Using '>=' when only '>' is needed
3. Given the table Employees with columns id, name, and salary, what rows will this query return?
SELECT * FROM Employees WHERE salary <= 50000;
medium
A. All employees with salary greater than 50000
B. All employees with salary exactly 50000 only
C. All employees with salary less than or equal to 50000
D. No employees, syntax error
Solution
Step 1: Understand the comparison operator used
The operator '<=' means 'less than or equal to', so it selects salaries 50000 or less.
Step 2: Interpret the query result
The query returns all rows where salary is 50000 or below, not just exactly 50000 or above 50000.
Final Answer:
All employees with salary less than or equal to 50000 -> Option C
Quick Check:
salary <= 50000 means salary ≤ 50000 [OK]
Hint: <= means less than or equal to [OK]
Common Mistakes:
Thinking <= means only equal
Confusing <= with <
Assuming syntax error in query
4. Identify the error in this SQL query:
SELECT * FROM Products WHERE price <>;
medium
A. Wrong comparison operator used
B. Incorrect table name
C. Missing SELECT keyword
D. Missing value after comparison operator
Solution
Step 1: Analyze the WHERE clause
The operator '<>' means 'not equal', but it must be followed by a value to compare.
Step 2: Identify syntax error
Here, '<>' is not followed by any value, causing a syntax error.
Final Answer:
Missing value after comparison operator -> Option D
Quick Check:
Comparison operators need a value after them [OK]
Hint: Comparison operators must have a value after them [OK]
Common Mistakes:
Leaving out value after operator
Confusing <> with != (both valid but must have value)
Assuming table or SELECT keyword is missing
5. You want to select all orders from the Orders table where the order_date is after January 1, 2023, and the total_amount is at least 100. Which query correctly uses WHERE with comparison operators?
hard
A. SELECT * FROM Orders WHERE order_date > '2023-01-01' AND total_amount >= 100;
B. SELECT * FROM Orders WHERE order_date >= '2023-01-01' OR total_amount > 100;
C. SELECT * FROM Orders WHERE order_date < '2023-01-01' AND total_amount > 100;
D. SELECT * FROM Orders WHERE order_date = '2023-01-01' AND total_amount = 100;
Solution
Step 1: Understand the date condition
We want orders after January 1, 2023, so use 'order_date > '2023-01-01''.
Step 2: Understand the amount condition
We want total_amount at least 100, so use 'total_amount >= 100'. Both conditions must be true, so use AND.
Step 3: Check each option
SELECT * FROM Orders WHERE order_date > '2023-01-01' AND total_amount >= 100; matches both conditions correctly. SELECT * FROM Orders WHERE order_date >= '2023-01-01' OR total_amount > 100; uses OR and >= for date, which is incorrect. SELECT * FROM Orders WHERE order_date < '2023-01-01' AND total_amount > 100; uses < for date, wrong direction. SELECT * FROM Orders WHERE order_date = '2023-01-01' AND total_amount = 100; uses = which is too strict.
Final Answer:
SELECT * FROM Orders WHERE order_date > '2023-01-01' AND total_amount >= 100; -> Option A
Quick Check:
Use > for after date, >= for at least amount, AND to combine [OK]
Hint: Use AND to combine conditions, > for after date, >= for minimum amount [OK]
Common Mistakes:
Using OR instead of AND
Using >= for date when strictly after is needed
Using = instead of comparison operators
Recommended
Ready to prove it?
Pass the test and this pattern moves unknownstrongwhile earning +1 Grip toward your certificate.