[英]select multiple columns from another table where field contains array
I have two table 我有两个桌子
phi_ads {id,files}
phi_files {id,file}
The problem is phi_ads
contains array for example (20,21) this numbers is id for phi_files
问题是
phi_ads
包含例如数组(20,21),此数字是phi_files
ID
So I need to select all this files 所以我需要选择所有这些文件
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
for note phi_ads.files = "102,103"
so return only first file , but I need to return all file in phi_files
注意
phi_ads.files = "102,103"
所以只返回第一个文件,但是我需要返回phi_files
所有文件
I am new. 我是新的。
Use IN operator , The IN operator allows you to specify multiple values in a WHERE clause. 使用IN运算符,可以使用IN运算符在WHERE子句中指定多个值。
phi_ads.files In (102,103)
Update 更新资料
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
Update 2 更新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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.