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
- A simple comparison:
sql
SELECT *
FROM Employees
WHERE Age = 30;- Selects only employees whose age is 30.
- A range comparison:
sql
SELECT *
FROM Employees
WHERE Age > 25 AND Age < 40;- Selects employees between 26 and 39 years old.
- A set-membership check:
sql
SELECT *
FROM Employees
WHERE DepartmentID IN (101, 102);- Selects employees from departments 101 or 102.
- Using patterns:
sql
SELECT *
FROM Employees
WHERE Name LIKE 'A%';- Selects employees whose names start with the letter "A".
Notes:
WHEREis applied before grouping (GROUP BY) and sorting (ORDER BY).- Conditions can be combined with
AND,OR,NOT.
Put simply,
WHEREis SQL's tool for filtering out unneeded rows and selecting only the data you need.
Short Answer
Interview readyPremium
A concise answer to help you respond confidently on this topic during an interview.