(Learn how to use the WHERE clause to filter rows based on specified conditions.)
Summary: in this tutorial, you will learn how to use the MySQL WHERE
clause in the SELECT
statement to filter rows from the result set.
Introduction to MySQL WHERE clause
The WHERE
clause allows you to specify a search_condition for the rows returned by a query. The following shows the syntax of the WHERE
clause:
SELECT
select_list
FROM
table_name
WHERE
search_condition;
The search_condition
is a combination of one or more expressions using the logical operator:
The followings are the syntax that can be use with WHERE
AND
OR
BETWEEN low AND high
LIKE
IN
NOT IN
IS NULL
COMAPARSION
NOT BETWEEN low AND high
LIMIT
In MySQL, a predicate is a Boolean expression that evaluates to TRUE
, FALSE
, or UNKNOWN
.
The SELECT
statement will include any row that satisfies the search_condition
in the result set.
Besides the SELECT
statement, you can use the WHERE
clause in the UPDATE
or DELETE
statement to specify which rows to update or delete.
When executing a SELECT
statement with a WHERE
clause, MySQL evaluates the WHERE
clause after the FROM
clause and before the SELECT
and ORDER BY
clauses:
MySQL WHERE clause examples
We’ll use the employees
table from the sample database for the demonstration:
