表1
id(int) | name(varchar)
1 | at,bat
2 | cat,at,bat,mat
3 | mat,cat
4 | sat,bat
表2
id(int) | type(varchar)
1 | at
2 | mat
如您所见,table1包含csv字符串。现在,我需要从id
中Table 1
来获取name
,Table2
存在于{{1}}类型字段中。
有没有任何纯mysql查询方式这样做?如果没有,在大型记录集的情况下,最有效的方法是什么?
答案 0 :(得分:5)
select distinct t1.id
from table1 t1
join table2 t2 on find_in_set(t2.type, t1.name) > 0
答案 1 :(得分:2)
请参阅here
select a.ids as id1, b.ids as id2, a.name,b.type
from table1 a
inner join table2 b on find_in_set(b.type,a.name)