为了更快的查询,您需要使用MySQL IN()。让我们首先创建一个表-
create table DemoTable1538 -> ( -> ClientId int, -> ClientName varchar(20) -> );
使用插入命令在表中插入一些记录-
insert into DemoTable1538 values(101,'Chris'); insert into DemoTable1538 values(102,'Robert'); insert into DemoTable1538 values(103,'Bob'); insert into DemoTable1538 values(104,'Adam');
使用select语句显示表中的所有记录-
select * from DemoTable1538;
这将产生以下输出-
+----------+------------+ | ClientId | ClientName | +----------+------------+ | 101 | Chris | | 102 | Robert | | 103 | Bob | | 104 | Adam | +----------+------------+ 4 rows in set (0.00 sec)
以下显示我们可以快速查询多个值-
select * from DemoTable1538 where ClientId IN(101,103,104);
这将产生以下输出-
+----------+------------+ | ClientId | ClientName | +----------+------------+ | 101 | Chris | | 103 | Bob | | 104 | Adam | +----------+------------+ 3 rows in set (0.00 sec)