🔍 WHERE Clause in SQL
Last Updated: 7th January 2026
The WHERE clause is used to filter rows in a query.
It ensures that only required records are returned based on a condition.
WHEREapplies conditions to data- It filters rows, not columns
- It works with comparison and logical operators
Hinglish Tip 🗣:
WHEREka kaam hai — kaunsa data chahiye aur kaunsa nahi, ye decide karna.
🧾 Basic Syntax of WHERE
SELECT column_name
FROM table_name
WHERE condition;
conditiondecides which rows are selected- Rows that do not satisfy the condition are excluded
⚖️ Comparison Operators in WHERE
Common operators used with WHERE:
=equal to!=or<>not equal to>greater than<less than>=greater than or equal to<=less than or equal to
SELECT name
FROM students
WHERE age >= 18;
Logical Operators in WHERE
WHERE can combine multiple conditions.
AND→ all conditions must be trueOR→ at least one condition must be trueNOT→ negates a condition
SELECT *
FROM students
WHERE marks > 70 AND age >= 18;
WHERE with NULL Values
IS NULL→ checks if a column has aNULLvalueIS NOT NULL→ checks if a column does not have aNULLvalue
SELECT *
FROM students
WHERE age IS NULL;
SELECT *
FROM students
WHERE age IS NOT NULL;
🧪 WHERE with BETWEEN, IN, LIKE Operators
INandNOT INoperators- Let say
WHERE marks = 30 OR marks = 50 OR marks = 70 - Use When There is multiple condition join using
ORoperator - e.g.
WHERE marks IN (30, 50, 70) - e.g.
WHERE marks NOT IN (30, 50, 70)
- Let say
BETWEENoperator- Let say
WHERE marks >= 60 AND marks <= 80 - Use When There is a range of condition join using
ANDoperator - e.g.
WHERE marks BETWEEN 60 AND 80
- Let say
LIKEAndNOT LIKEoperator- It is used to match a pattern in a column
%charend with given characters- e.g.
WHERE name LIKE '%A'
- e.g.
char%start with given characters- e.g.
WHERE name LIKE 'A%'
- e.g.
%char%contains given characters- e.g.
WHERE name LIKE '%A%'
- e.g.
_charTwo characters long and end with given characters- e.g.
WHERE name LIKE '_A'
- e.g.
Note: We will cover
Regular Expressions (regex)in the next section.
Subqueries in WHERE
Syntax:
SELECT column_name
FROM table_name
WHERE column_name IN (SELECT column_name FROM table_name);
Example:
SELECT name
FROM students
WHERE age > (SELECT age FROM students WHERE name LIKE "A%");