Description

The SQL keyword WHERE is used to specify conditions to select specific records from a database, from one or more tables.

  • It can be used on different types of SQL statements, like SELECT, UPDATE, DELETE, etc.,

Operators Allowed on WHERE Clause

SQL supports a number of different types of operators that can be used in the WHERE clause, and here is a list of the most commonly used.

See SQL Operators for more details on operators.

Operator Description Example
= Equal WHERE salary = 20000
> Greater than WHERE salary > 20000
< Less than WHERE salary < 20000
>= Greater than or equal WHERE salary >= 20000
<= Less than or equal WHERE salary <= 20000
LIKE Simple pattern matching WHERE employee_name LIKE 'Tony%'
IN Check whether a specified value matches any value in a list or subquery WHERE employee_id IN (1,2,3)
BETWEEN Check whether a specified value is within a range of values WHERE employee_id BETWEEN 1 AND 3

SELECT With WHERE

The below SQL fetches records from a table based on the WHERE conditions.

SELECT * FROM employees
WHERE employee_id IN (1,2,3,4,5);

UPDATE With WHERE

The below SQL updates the table records based on the WHERE conditions.

UPDATE employees 
SET salary = 20000 
WHERE employee_id IN (1,2,3,4,5);

DELETE With WHERE

The below SQL deletes the table records based on the WHERE conditions.

DELETE employees
WHERE employee_id IN (1,2,3,4,5);

Related Links