SQL WHERE Clause – Complete Guide with Examples (2026-27)
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:
SELECT— to filter which rows to readUPDATE— to filter which rows to changeDELETE— to filter which rows to remove
✅ 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 to | WHERE Country = 'USA' |
!= or <> | Not equal to | WHERE Country != 'USA' |
> | Greater than | WHERE Price > 50 |
< | Less than | WHERE Price < 100 |
>= | Greater than or equal | WHERE Salary >= 50000 |
<= | Less than or equal | WHERE Salary <= 80000 |
BETWEEN | Within a range | WHERE Price BETWEEN 10 AND 50 |
LIKE | Pattern matching | WHERE Name LIKE 'P%' |
IN | Match any value in a list | WHERE Country IN ('USA','UK') |
IS NULL | Value is empty/missing | WHERE Email IS NULL |
IS NOT NULL | Value is not empty | WHERE Email IS NOT NULL |
AND | Both conditions must be true | WHERE Dept='IT' AND Salary>50000 |
OR | Either condition can be true | WHERE Dept='IT' OR Dept='HR' |
NOT | Reverses the condition | WHERE 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.
| CustomerID | Name | Country |
|---|---|---|
| 1 | Anni | USA |
| 2 | Sujan | USA |
| 3 | Boult | India |
| 4 | Marco | Italy |
✅ SELECT Query:-
SELECT *
FROM Customers
WHERE Country = 'USA';
✅ Result:-
| CustomerID | Name | Country |
|---|---|---|
| 1 | Anni | USA |
| 2 | Sujan | USA |
'USA'. Numbers do not need quotes: WHERE Price > 50.
✅ Example 2 – Filter by Price (> operator)
Retrieve products that cost more than 50.
| ProductName | Price |
|---|---|
| Pen | 10 |
| Laptop | 90000 |
| Mobile | 70000 |
| Notebook | 30 |
✅ SELECT Query:-
SELECT ProductName, Price
FROM Products
WHERE Price > 50;
✅ Result:-
| ProductName | Price |
|---|---|
| Laptop | 90000 |
| Mobile | 70000 |
✅ Example 3 – Filter Employees by Department
Select employees from the IT department only.
✅ SELECT Query:-
SELECT Name, Department
FROM Employees
WHERE Department = 'IT';
✅ Result:-
| Name | Department |
|---|---|
| Pramod | IT |
| Pooja | IT |
| Rajesh | IT |
| Rupesh | IT |
✅ 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';
✅ 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%';
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;
✅ Example 7 – Filter Employees Hired After 2025
✅ SELECT Query:-
SELECT *
FROM Employees
WHERE HireDate > '2025-01-01';
YYYY-MM-DD for date comparisons in SQL to ensure compatibility across all database systems.
✅ Common SQL WHERE Clause Mistakes to Avoid
Wrong:
WHERE Country = USA — causes an error.Correct:
WHERE Country = 'USA'
Wrong:
WHERE Email = NULL — always returns no rows.Correct:
WHERE Email IS NULL
Mixing AND and OR without parentheses gives wrong results. Always wrap OR conditions in brackets:
WHERE (Dept='IT' OR Dept='HR') AND Salary > 50000.
Omitting WHERE in an UPDATE or DELETE affects every row in the table. Always double-check your WHERE clause before running these statements.
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)
=, !=, >, <, >=, <=, BETWEEN, LIKE, IN, IS NULL, IS NOT NULL, AND, OR, and NOT.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.WHERE (Department = 'IT' OR Department = 'HR') AND Salary > 50000.% to match any number of characters and _ for a single character. Example: WHERE Name LIKE 'P%' returns all names starting with P.LOWER() or UPPER() functions to normalize comparisons across databases.