从 MySQL 表中选择行并使用 IN() 进行显示
我们首先创建一个表 -
mysql> create table DemoTable778 ( ClientId varchar(100), ClientName varchar(100) ); Query OK, 0 rows affected (1.05 sec)
使用 `insert` 命令在表中插入一些记录 -
mysql> insert into DemoTable778 values('J-101','John'); Query OK, 1 row affected (0.20 sec) mysql> insert into DemoTable778 values('A-102','Adam'); Query OK, 1 row affected (0.23 sec) mysql> insert into DemoTable778 values('C-103','Chris'); Query OK, 1 row affected (0.12 sec) mysql> insert into DemoTable778 values('D-104','David'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable778 values('R-105','Robert'); Query OK, 1 row affected (0.41 sec)
使用 `select` 语句显示表中的所有记录 -
mysql> select *from DemoTable778;
这将产生以下输出 -
+----------+------------+ | ClientId | ClientName | +----------+------------+ | J-101 | John | | A-102 | Adam | | C-103 | Chris | | D-104 | David | | R-105 | Robert | +----------+------------+ 5 rows in set (0.00 sec)
从 MySQL 表中选择行并使用 IN() 进行显示 -
mysql> select *from DemoTable778 where ClientId IN('J-101','A-102','C-103','D-104','R-105');
这将产生以下输出 -
+----------+------------+ | ClientId | ClientName | +----------+------------+ | J-101 | John | | A-102 | Adam | | C-103 | Chris | | D-104 | David | | R-105 | Robert | +----------+------------+ 5 rows in set (0.00 sec)
广告