SQL Tutorial

SQL WHERE Clause – Complete Guide with Examples (2026-27)

By Pramod Behera  ·  Updated:  ·  Reading time: 8 min

The SQL WHERE clause is used to filter rows from a table and return only the records that meet a specific condition. It is one of the most commonly used SQL commands, working with SELECT, UPDATE, DELETE and INSERT statements. In this beginner-friendly guide you will learn the WHERE clause syntax with real examples covering operators like =, >, <, BETWEEN, LIKE, IN, AND, OR and NOT — plus common mistakes to avoid and FAQs answered.



✅ What is the SQL WHERE Clause?

The SQL WHERE clause is used to filter records in a query. It tells the database to return only the rows where the given condition is true. Without a WHERE clause, a SELECT query returns all rows from the table.

The WHERE clause can be used in:

💡 Key Point: Always use a WHERE clause with UPDATE and DELETE statements. Without it, every row in the table will be updated or deleted.

✅ SQL WHERE Clause – Basic Syntax

SELECT column1, column2, ...
FROM table_name
WHERE condition;

SELECT:- Specifies the columns you want to retrieve.

FROM:- Specifies the table to query.

WHERE:- Specifies the condition that rows must meet to be returned.


✅ SQL WHERE Clause – Operators Reference Table

You can use the following operators inside a WHERE clause to build filter conditions:

Operator Meaning Example
=Equal toWHERE Country = 'USA'
!= or <>Not equal toWHERE Country != 'USA'
>Greater thanWHERE Price > 50
<Less thanWHERE Price < 100
>=Greater than or equalWHERE Salary >= 50000
<=Less than or equalWHERE Salary <= 80000
BETWEENWithin a rangeWHERE Price BETWEEN 10 AND 50
LIKEPattern matchingWHERE Name LIKE 'P%'
INMatch any value in a listWHERE Country IN ('USA','UK')
IS NULLValue is empty/missingWHERE Email IS NULL
IS NOT NULLValue is not emptyWHERE Email IS NOT NULL
ANDBoth conditions must be trueWHERE Dept='IT' AND Salary>50000
OREither condition can be trueWHERE Dept='IT' OR Dept='HR'
NOTReverses the conditionWHERE NOT Country='USA'

✅ Example 1 – Filter by Country (= operator)

The Customers table below has records from different countries. We want only customers from the USA.

Customers
CustomerIDNameCountry
1AnniUSA
2SujanUSA
3BoultIndia
4MarcoItaly

SELECT Query:-

SELECT *
FROM Customers
WHERE Country = 'USA';

Result:-

CustomerIDNameCountry
1AnniUSA
2SujanUSA
💡 Tip: Always put string values in single quotes: 'USA'. Numbers do not need quotes: WHERE Price > 50.

✅ Example 2 – Filter by Price (> operator)

Retrieve products that cost more than 50.

Products
ProductNamePrice
Pen10
Laptop90000
Mobile70000
Notebook30

SELECT Query:-

SELECT ProductName, Price
FROM Products
WHERE Price > 50;

Result:-

ProductNamePrice
Laptop90000
Mobile70000

✅ Example 3 – Filter Employees by Department

Select employees from the IT department only.

SELECT Query:-

SELECT Name, Department
FROM Employees
WHERE Department = 'IT';

Result:-

NameDepartment
PramodIT
PoojaIT
RajeshIT
RupeshIT

✅ Example 4 – Filter by Date Range (BETWEEN)

The BETWEEN operator returns rows where a value falls within a specified range — including both endpoints.

SELECT Query:-

SELECT *
FROM Orders
WHERE OrderDate BETWEEN '2025-02-01' AND '2025-11-30';
💡 Tip: BETWEEN works with numbers, dates, and text. The range is inclusive — both the start and end values are included in results.

✅ Example 5 – Pattern Matching with LIKE

The LIKE operator is used for pattern matching in text columns. Use % to match any number of characters and _ to match exactly one character.

SELECT Query – Names starting with 'P':-

SELECT Name FROM Employees
WHERE Name LIKE 'P%';

SELECT Query – Names containing 'mod':-

SELECT Name FROM Employees
WHERE Name LIKE '%mod%';
💡 Wildcard Guide:
P% — starts with P  |  %ra — ends with ra  |  %mod% — contains mod  |  P_a — P, any char, then a

✅ Example 6 – Combining AND & OR Conditions

Use AND when all conditions must be true. Use OR when any one condition is enough.

SELECT Query – AND example:-

SELECT * FROM Employees
WHERE Department = 'IT' AND Salary > 50000;

SELECT Query – OR example:-

SELECT * FROM Employees
WHERE Department = 'IT' OR Department = 'HR';

SELECT Query – Combined AND + OR with parentheses:-

SELECT * FROM Employees
WHERE (Department = 'IT' OR Department = 'HR')
AND Salary > 50000;
⚠️ Important: When mixing AND and OR, always use parentheses to control the order of evaluation. Without them, AND is evaluated before OR, which may give unexpected results.

✅ Example 7 – Filter Employees Hired After 2025

SELECT Query:-

SELECT *
FROM Employees
WHERE HireDate > '2025-01-01';
💡 Note: Always use the ISO date format YYYY-MM-DD for date comparisons in SQL to ensure compatibility across all database systems.

✅ Common SQL WHERE Clause Mistakes to Avoid

❌ Mistake 1: Forgetting quotes around string values
Wrong: WHERE Country = USA — causes an error.
Correct: WHERE Country = 'USA'
❌ Mistake 2: Using = for NULL values
Wrong: WHERE Email = NULL — always returns no rows.
Correct: WHERE Email IS NULL
❌ Mistake 3: Missing parentheses with AND + OR
Mixing AND and OR without parentheses gives wrong results. Always wrap OR conditions in brackets: WHERE (Dept='IT' OR Dept='HR') AND Salary > 50000.
❌ Mistake 4: UPDATE or DELETE without WHERE
Omitting WHERE in an UPDATE or DELETE affects every row in the table. Always double-check your WHERE clause before running these statements.
❌ Mistake 5: Wrong date format
Use ISO format 'YYYY-MM-DD' for dates. Writing '01/01/2025' may work in some databases but fail in others.

✅ Frequently Asked Questions (FAQ)

What is the SQL WHERE clause?
The SQL WHERE clause filters rows returned by a query. It works with SELECT, UPDATE, DELETE, and INSERT statements. Only rows where the condition is true are returned or affected.
What operators can be used in a SQL WHERE clause?
You can use =, !=, >, <, >=, <=, BETWEEN, LIKE, IN, IS NULL, IS NOT NULL, AND, OR, and NOT.
What is the difference between WHERE and HAVING in SQL?
WHERE filters individual rows before grouping. HAVING filters groups of rows after a GROUP BY clause. Always use WHERE for row-level conditions and HAVING for group-level conditions.
Can I use AND and OR together in a WHERE clause?
Yes. You can combine AND and OR in the same WHERE clause. Always use parentheses to control the order of evaluation. Example: WHERE (Department = 'IT' OR Department = 'HR') AND Salary > 50000.
What does WHERE LIKE do in SQL?
The LIKE operator performs pattern matching on text. Use % to match any number of characters and _ for a single character. Example: WHERE Name LIKE 'P%' returns all names starting with P.
Is the SQL WHERE clause case sensitive?
It depends on the database. MySQL string comparisons are case-insensitive by default. PostgreSQL is case-sensitive. Use LOWER() or UPPER() functions to normalize comparisons across databases.

✍️ About the Author: Pramod Behera

Pramod Behera is a SAP and SQL educator with 10+ years of experience in enterprise software and database systems. He founded LearnToSAP.com to help beginners learn SAP and SQL concepts through clear, practical, real-world examples. His tutorials have helped thousands of students and IT professionals across India and beyond.