Curriculum
Course: SQL
Login

Curriculum

SQL

SQL References

0/80

MySQL Functions

0/139

SQL Server Functions

0/84

SQL Quick Ref

0/1
Text lesson

WHERE

SELECT

The WHERE clause filters a result set to include only records that meet a specified condition.

The following SQL statement selects all customers from “Mexico” in the “Customers” table:

Example

SELECT * FROM Customers
WHERE Country=‘Mexico’

In SQL, single quotes are required around text values (although many database systems also accept double quotes), while numeric fields should not be enclosed in quotes.

Example

SELECT * FROM Customers
WHERE CustomerID=1

Note: The WHERE clause is not limited to SELECT statements; it is also used in UPDATE, DELETE statements, etc.!

The following operators can be utilized in the WHERE clause:

 

Operator

Description

=

Equal

<> 

Not equal. Note: In certain SQL versions, this operator may be represented as !=

> 

Greater than

Less than

>=

Greater than or equal

<=

Less than or equal

BETWEEN

Between a specified range.

LIKE

Search for a pattern.

IN

To specify multiple potential values for a column.