要查找行,请使用FIND_IN_SET()。让我们首先创建一个表-
mysql> create table DemoTable -> ( -> ListOfIds varchar(200) -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values('100,2093,678,686'); mysql> insert into DemoTable values('0595,9585,4885,95959'); mysql> insert into DemoTable values('0059954,95986884,9059596,9005');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
输出结果
+-------------------------------+ | ListOfIds | +-------------------------------+ | 100,2093,678,686 | | 0595,9585,4885,95959 | | 0059954,95986884,9059596,9005 | +-------------------------------+ 3 rows in set (0.00 sec)
以下是查找特定行的查询,该行在MySQL中具有多个用逗号分隔的ID-
mysql> select *from DemoTable where FIND_IN_SET('9005', ListOfIds);
输出结果
+-------------------------------+ | ListOfIds | +-------------------------------+ | 0059954,95986884,9059596,9005 | +-------------------------------+ 1 row in set (0.00 sec)