目录

SQL WHERE 关键字


WHERE

这个WHERE命令过滤结果集以仅包含满足指定条件的记录。

以下 SQL 语句从 "Customers" 表中的 "Mexico" 选择所有客户:

示例

SELECT * FROM Customers
WHERE Country='Mexico';
亲自试一试 »

SQL 需要将文本值用单引号括起来(大多数数据库系统也允许双引号)。

但是,数字字段不应括在引号中:

示例

SELECT * FROM Customers
WHERE CustomerID=1;
亲自试一试 »

笔记:WHERE子句不仅用在SELECT语句中,它还用在UPDATE、DELETE语句等中!

WHERE 子句中可以使用以下运算符:

Operator Description
= Equal
<> Not equal. Note: In some versions of SQL this operator may be written as !=
> 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 for a column