我有两个表
phi_ads {id,files}
phi_files {id,file}
问题是phi_ads
包含数组例如(20,21)这些数字是phi_files
的id
I try this
select a.name,d.*,f.* from phi_ads d
inner join phi_areas a on a.id = d.area
inner join phi_files f on f.id = d.files
where d.id=42
注意phi_ads.files = "102,103"
,所以只返回第一个文件,但我需要返回phi_files
我是新人
使用IN操作符,IN操作符允许您在WHERE子句中指定多个值。
phi_ads.files In (102,103)
参考 select a.name,d.*,f.* from phi_ads d
inner join phi_areas a on a.id = d.area
inner join phi_files f on FIND_IN_SET( f.id , d.files )
where d.id=42
更新2
select a.name,d.*,GROUP_CONCAT(f.name) as name from phi_ads d
inner join phi_areas a on a.id = d.area
inner join phi_files f on FIND_IN_SET( f.id , d.files )
where d.id=42