mysql> desc test1
-> ;
+-------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+------------------+------+-----+---------+----------------+
| id | int(11) unsigned | NO | PRI | NULL | auto_increment |
+-------+------------------+------+-----+---------+----------------+
mysql> desc test2;
+---------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------+------------------+------+-----+---------+----------------+
| id | int(11) unsigned | NO | PRI | NULL | auto_increment |
| ids_str | varchar(32) | YES | | NULL | |
+---------+------------------+------+-----+---------+----------------+
ids_str是一个字符串。
ids_str="1,2,3"
select * from test1 where id in (select ids_str from test2)
即:
select * from test1 where id in ("1,2,3")
select * from test1 where find_in_set(id,(select ids_str from test2));