MySQL选择查询有多个WHERE?
要实现多个WHERE,请使用IN()
IN MySQL。
以下是语法:
select *from yourTableName where yourColumnName IN(yourValue1,yourValue2,...N);
让我们首先创建一个表-
mysql> create table DemoTable(
Id int,
Name varchar(100)
);
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values(10,'John');mysql> insert into DemoTable values(59,'Carol');
mysql> insert into DemoTable values(20,'Sam');
mysql> insert into DemoTable values(45,'David');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
输出结果
+------+-------+| Id | Name |
+------+-------+
| 10 | John |
| 59 | Carol |
| 20 | Sam |
| 45 | David |
+------+-------+
4 rows in set (0.00 sec)
以下是实现多个WHERE的查询-
mysql> select *from DemoTable where Id IN(59,45);
输出结果
+------+-------+| Id | Name |
+------+-------+
| 59 | Carol |
| 45 | David |
+------+-------+
2 rows in set (0.14 sec)
以上是 MySQL选择查询有多个WHERE? 的全部内容, 来源链接: utcz.com/z/331188.html