MySQL where子句与选择,插入,更新和删除子句一起使用,以过滤结果。它指定了您必须执行操作的特定位置。
SELECT field1, field2,...fieldN table_name1, table_name2... [WHERE condition1 [AND [OR]] condition2.....
WHERE 子句在任何编程语言中的作用均类似于 if条件,该子句用于将给定值与MySQL表中可用的字段值进行比较,如果外部的给定值等于MySQL表中的可用字段值,则它将返回该行。
假设字段A=10,字段B=20,则-
Operator | 描述 | Example |
---|---|---|
= | 等于 | (A=B) is not true. |
!= | 不等于 | (A != B) is true. |
> | 大于 | (A > B) is not true. |
< | 小于 | (A < B) is true. |
>= | 大于或等于 | (A >= B) is not true. |
<= | 小于或等于 | (A <= B) is true.\ |
让无涯教程举个例子来检索来自表"officers"的数据。
链接:https://www.learnfk.comhttps://www.learnfk.com/mysql/mysql-where.html
来源:LearnFk无涯教程网
表结构如下 :
执行此查询:
SELECT * FROM officers WHERE address = 'Mau';
输出:
在此示例中,无涯教程正在从表"officers"中检索数据和条件。
执行以下查询:
SELECT * FROM officers WHERE address = 'Lucknow' AND officer_id
输出:
执行以下查询:
SELECT * FROM officers WHERE address = 'Lucknow' OR address = 'Mau';
输出:
您还可以使用where子句完全使用和&或条件。
执行以下查询:
SELECT * FROM officers WHERE (address = 'Mau' AND officer_name = 'Ajeet') OR (officer_id < 5 );
输出:
祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)