Open In App

SQL - WHERE Clause

Last Updated : 12 Nov, 2025
Comments
Improve
Suggest changes
103 Likes
Like
Report

The SQL WHERE clause filters rows based on one or more conditions, so your query returns (or modifies) only the records that match. It’s used across SELECT, UPDATE, and DELETE statements, and works with data from a single table or from multiple tables after joins

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

Emp

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 Emp1 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 Emp1 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 Emp1 
WHERE Age BETWEEN 22 AND 24;

Output:

Screenshot-4

Example 4: Where Clause with LIKE Operator

It is used to fetch filtered data by searching for a particular pattern in the where clause. In this example we want to find records of Employees where Name starts with the letter. The '%'(wildcard) signifies the later characters here which can be of any length and value. 

Query:

SELECT * 
FROM Employee
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 Emp1 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
Suggested Quiz
6 Questions

Which operator is used to match a pattern in SQL?

  • A

    IN

  • B

    BETWEEN

  • C

    LIKE

  • D

    ANY

Explanation:

LIKE is used for pattern matching with wildcards.

Which query filters employees aged 25 or older?

  • A

    SELECT * FROM Emp WHERE Age >= 25;

  • B

    SELECT * FROM Emp WHERE Age > 25 AND Age < 25;

  • C

    SELECT Age FROM Emp;

  • D

    SELECT * WHERE Age >= 25;

Explanation:

Age >= 25 correctly returns employees aged 25 or more.

What does the IN operator allow you to do?

  • A

    Compare two columns

  • B

    Check multiple possible values

  • C

    Search NULL values

  • D

    Sort values

Explanation:

IN checks whether a column matches any value in the list.

Which operator is used in a WHERE clause to match a pattern in text data?

  • A

    LIKE

  • B

    BETWEEN

  • C

    IN

  • D

    <>

Explanation:

LIKE is used for pattern matching with wildcards such as % or _.

Which query correctly retrieves employees whose age is between 25 and 30 (inclusive)?

  • A

    SELECT * FROM Emp WHERE Age > 25 AND Age < 30;

  • B

    SELECT * FROM Emp WHERE Age BETWEEN 25 AND 30;

  • C

    SELECT * FROM Emp WHERE Age IN (25 TO 30);

  • D

    SELECT * FROM Emp HAVING Age BETWEEN 25 AND 30;

Explanation:

BETWEEN includes both the start and end values.

What does the IN operator do in a WHERE clause?

  • A

    Finds approximate numeric ranges

  • B

    Matches any value within a specified list

  • C

    Sorts values before filtering

  • D

    Filters after grouping

Explanation:

IN allows multiple possible match values in a single condition.

Quiz Completed Successfully
Your Score :   2/6
Accuracy :  0%
Login to View Explanation
1/6 1/6 < Previous Next >

Article Tags :

Explore