SQL WHERE 子句
- WHERE 子句用于过滤记录。
- WHERE 子句用于提取满足指定标准的记录。
SQL WHERE 语法
SELECT column1, column2, ...
FROM table_name
WHERE condition;
注意: WHERE子句不仅用于SELECT语法,还用于UPDATE,DELETE语法等!
WHERE子句可以与以下类型的SQL语句一起使用:
- UPDATE
- DELETE
(1) UPDATE语句:
UPDATE "table_name"
SET "column_1" = [new value]
WHERE "condition";
(2) DELETE语句:
DELETE FROM "table_name"
WHERE "condition";
WHERE 子句实例:
需求:SQL语句从"Customers"表中选择其国家为"Mexico"的所有客户:
SELECT * FROM Customers
WHERE Country='Mexico';
OR(或) 运算符的查询子句:
SELECT * FROM Customers
WHERE Country='Mexico' OR PostalCode='05021';