56,912
社区成员




select id1,name1 from (
select test1.*,find_in_set(test1.id1,test2.name2) as num
from test1,test2
where find_in_set(test1.id1,test2.name2)>0
order by num) temp
select id1,name1 from (
select test1.*,instr(test2.name2,test1.id1) as num
from test1,test2
where instr(test2.name2,test1.id1) >0
order by num) temp
select a.id1,a.name1
from test1 a join test2 b on instr(b.name2,a.id1) >0
mysql> select *from test1;
+------+-------+
| id1 | name1 |
+------+-------+
| 01 | a1 |
| 02 | a2 |
| 03 | a3 |
| 04 | a4 |
| 05 | a5 |
| 06 | a6 |
| 07 | a7 |
| 08 | a8 |
| 09 | a9 |
| 10 | a10 |
+------+-------+
10 rows in set (0.00 sec)
mysql> select *From test2;
+------+----------------+
| id2 | name2 |
+------+----------------+
| 11 | 06,02,03,09,05 |
+------+----------------+
1 row in set (0.00 sec)
mysql> select test1.* from test1,test2
-> where instr(test2.name2,test1.id1) >0;
+------+-------+
| id1 | name1 |
+------+-------+
| 02 | a2 |
| 03 | a3 |
| 05 | a5 |
| 06 | a6 |
| 09 | a9 |
+------+-------+
5 rows in set (0.00 sec)