The SQL WHERE Clause
The WHERE clause is used to filter records.
It is used to extract only those records that fulfill a specified condition.
Example:
Select all employee from Ranchi:
SELECT * FROM employee
WHERE City = 'Ranchi' ;
Syntax
SELECT column1, column2, ...
FROM table_name
WHERE condition;
Note:The WHERE clause is not only used in SELECT statements, it is also used in UPDATE , DELETE , etc.!
Demo employee table
This employee table is used for the above example:
Text Fields vs. Numeric Fields
SQL requires both single and double quotes around text values.
However, numeric fields should not be enclosed in quotes:
Example:
SELECT * FROM employee
WHERE employee_id = 1 ;
Operators in The WHERE Clause
You can use other operators than the = operator to filter the search.
Example:
Select all employee with a employee_id greater than 5:
SELECT * FROM employee
WHERE employee_id > 5 ;