使用 MySQL IN() 来获取带下划线的某些列值
mysqlmysqli database
首先我们创建一个表 −
mysql> create table DemoTable1363 -> ( -> StudentId varchar(20) -> ); Query OK, 0 rows affected (0.57 sec)
使用 insert 命令在表中插入一些记录 −
mysql> insert into DemoTable1363 values('901'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable1363 values('702'); Query OK, 1 row affected (0.17 sec) mysql> insert into DemoTable1363 values('901_John_Doe'); Query OK, 1 row affected (0.10 sec) mysql> insert into DemoTable1363 values('1001_Carol_Taylor'); Query OK, 1 row affected (0.26 sec)
使用 select 语句显示表中的所有记录 −
mysql> select * from DemoTable1363;
这将产生以下输出 −
+-------------------+ | StudentId | +-------------------+ | 901 | | 702 | | 901_John_Doe | | 1001_Carol_Taylor | +-------------------+ 4 rows in set (0.00 sec)
以下是实现 IN() 的 MySQL 查询 −
mysql> select * from DemoTable1363 where StudentId IN('702','1001');
这将产生以下输出 −
+-----------+ | StudentId | +-----------+ | 702 | +-----------+ 1 row in set (0.00 sec)