我们可以使用MySQL WHERE子句获取多个值吗?
是的,我们可以获取,但是将MySQL OR用于条件。让我们首先创建一个-
mysql> create table DemoTable1421-> (
-> EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY,
-> EmployeeName varchar(20),
-> EmployeeSalary int
-> );
使用insert在表中插入一些记录-
mysql> insert into DemoTable1421(EmployeeName,EmployeeSalary) values('Chris',10000);mysql> insert into DemoTable1421(EmployeeName,EmployeeSalary) values('Bob',15000);
mysql> insert into DemoTable1421(EmployeeName,EmployeeSalary) values('David',8000);
mysql> insert into DemoTable1421(EmployeeName,EmployeeSalary) values('Carol',8500);
mysql> insert into DemoTable1421(EmployeeName,EmployeeSalary) values('Mike',14500);
使用选择显示表中的所有记录-
mysql> select * from DemoTable1421;
这将产生以下输出-
+------------+--------------+----------------+| EmployeeId | EmployeeName | EmployeeSalary |
+------------+--------------+----------------+
| 1 | Chris | 10000 |
| 2 | Bob | 15000 |
| 3 | David | 8000 |
| 4 | Carol | 8500 |
| 5 | Mike | 14500 |
+------------+--------------+----------------+
5 rows in set (0.00 sec)
这是使用OR获取多个值的查询-
mysql> select * from DemoTable1421 where EmployeeId=1 OR EmployeeName='David' OR EmployeeSalary=14500;
这将产生以下输出-
+------------+--------------+----------------+| EmployeeId | EmployeeName | EmployeeSalary |
+------------+--------------+----------------+
| 1 | Chris | 10000 |
| 3 | David | 8000 |
| 5 | Mike | 14500 |
+------------+--------------+----------------+
3 rows in set (0.00 sec)
以上是 我们可以使用MySQL WHERE子句获取多个值吗? 的全部内容, 来源链接: utcz.com/z/353445.html