Skip to main content

What does the WHERE operator do?

The WHERE operator in SQL is used to filter rows, that is, to select only the records satisfying a given condition.

Syntax:

sql
SELECT Column1, Column2, ... FROM Table_Name WHERE Condition;

Usage examples

  1. A simple comparison:
sql
SELECT * FROM Employees WHERE Age = 30;
  • Selects only employees whose age is 30.
  1. A range comparison:
sql
SELECT * FROM Employees WHERE Age > 25 AND Age < 40;
  • Selects employees between 26 and 39 years old.
  1. A set-membership check:
sql
SELECT * FROM Employees WHERE DepartmentID IN (101, 102);
  • Selects employees from departments 101 or 102.
  1. Using patterns:
sql
SELECT * FROM Employees WHERE Name LIKE 'A%';
  • Selects employees whose names start with the letter "A".

Notes:

  • WHERE is applied before grouping (GROUP BY) and sorting (ORDER BY).
  • Conditions can be combined with AND, OR, NOT.

Put simply, WHERE is SQL's tool for filtering out unneeded rows and selecting only the data you need.

Short Answer

Interview ready
Premium

A concise answer to help you respond confidently on this topic during an interview.