SQL - WHERE Clause

Last Updated : 14 Apr, 2026

SQL provides the WHERE clause to filter rows based on one or more conditions. It ensures that queries return or modify only the required records.

  • It filters data based on specified conditions.
  • It is used with SELECT, UPDATE, and DELETE statements.
  • It works with comparison and logical operators.

Example: First, we will create a demo SQL database and Employees table, on which we will use the WHERE Clause command.

Emp
Employees table

Query:

SELECT Name, Department, Salary
FROM Employees
WHERE Salary > 50000;

Output:

Select

Syntax:

SELECT column1, column2
FROM table_name
WHERE column_name operator value;
  • column1, column2: Columns you want to retrieve.
  • table_name: Table you are querying from.
  • operator: Comparison logic (e.g., =, <, >, LIKE).
  • value: The value or pattern to filter against.

Examples of WHERE Clause

We will create a basic employee table structure in SQL for performing all the where clause operation.

Screenshot-where

Example 1: Where Clause with Logical Operators

To fetch records of  Employee with age equal to 24.

Query:

SELECT * FROM Employees WHERE Age=24;

Output:

Screenshot-2

Example 2: WHERE with Comparison Operators

To fetch the EmpID, Name and Country of Employees with Age greater than 21. 

Query:

SELECT EmpID, Name, Country FROM Employees WHERE Age > 21;

Output:

Screenshot-3

Example 3: Where Clause with BETWEEN Operator

The BETWEEN operator is used to filter records within a specified range, and it includes both the start and end values. In this example, we want to find employees whose age is between 22 and 24, including both 22 and 24.

Query:

SELECT * FROM Employees
WHERE Age BETWEEN 22 AND 24;

Output:

Screenshot-4

Example 4: Where Clause with LIKE Operator

 The LIKE operator is used to filter data by matching a specific pattern in the WHERE clause. In this example, we retrieve records of employees whose names start with the letter 'L'.

  • The % wildcard represents any number of characters (including zero).
  • The _ wildcard represents exactly one character.

Query:

SELECT * FROM Employees 
WHERE Name LIKE 'L%';

Output:

Like-operator

Example 5: Where Clause with IN Operator

It is used to fetch the filtered data same as fetched by '=' operator just the difference is that here we can specify multiple values for which we can get the result set. Here we want to find the Names of Employees where Age is 21 or 23.

Query:

SELECT Name FROM Employees
WHERE Age IN (21,23);

Output:

SS

Operators Used in WHERE Clause

OperatorDescription
>Greater Than
>=Greater than or Equal to
<Less Than
<=Less than or Equal to
=Equal to
<>Not Equal to
BETWEENIn an inclusive Range
LIKESearch for a pattern
INTo specify multiple possible values for a column
Comment