SQL WHERE Keyword
The WHERE clause filters a result set to include only records that meet a specified condition. It is commonly used with SELECT, UPDATE, and DELETE statements.
- Text values must be enclosed in single quotes (‘value’).
- Numeric values must not be enclosed in quotes.
SQL WHERE Syntax
SQL
x
1
SELECT column1, column2, ...
2
FROM table_name
3
WHERE condition;
SQL WHERE with Text Value Example
This query selects all female patients (gender = ‘F’).
SQL
1
1
SELECT *
2
FROM Patients
3
WHERE gender = 'F';

SQL WHERE with Numeric Value Example
This query selects the patient with patient_id = 1.
SQL
1
1
SELECT *
2
FROM Patients
3
WHERE patient_id = 1;

SQL WHERE Supported Operators
You can use the following operators in the WHERE
clause:
Operator | Description |
---|---|
= | Equal |
<> or != | Not equal |
> | Greater than |
< | Less than |
>= | Greater than or equal |
<= | Less than or equal |
BETWEEN | Between a certain range |
LIKE | Search for a pattern |
IN | To specify multiple possible values |
SQL WHERE with Operator Example (BETWEEN)
This query selects patients with patient_id between 3 and 6.
SQL
1
1
SELECT *
2
FROM Patients
3
WHERE patient_id BETWEEN 3 AND 6;
