The WHERE clause is used to filter rows returned by a SQL query. It allows you to specify one or more conditions that records must satisfy before they are included in the result. WHERE can use comparison operators such as =, >, <, >=, <=, and <> and can also be combined with logical operators such as AND, OR, and NOT.
Large databases may contain millions of records, but business questions normally require only a specific subset of those records. WHERE allows analysts to retrieve only the data relevant to the business question.
A manager wants to see employees working in the Finance department. The analyst can use WHERE to filter the Employees table and return only Finance employees.
SELECT
EmployeeName,
Department,
Salary
FROM Employees
WHERE Department = 'Finance';
WHERE is used for filtering transactions by amount or date, employees by department, customers by location, products by category, and sales by region.
- WHERE filters rows.
- WHERE is commonly used with SELECT.
- Conditions are written after WHERE.
- WHERE can use comparison operators.
- WHERE can use AND, OR, and NOT.
- WHERE does not permanently modify the table.
What is the purpose of WHERE?
WHERE filters rows based on one or more specified conditions.
Does WHERE modify the original table?
No. WHERE filters the rows affected or returned by a SQL statement but does not permanently change the table.