简体   繁体   English

从另一个表中选择多个列,其中字段包含数组

[英]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)

Reference 参考

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.

相关问题 从 mysql 表中选择 WHERE field='$array'? - Select from mysql table WHERE field='$array'? 插入到多个列的select中,其中只有一列来自另一个表 - insert into select for multiple columns, where only one column is from another table Select from table where 子句 from array from another table - Select from table where clause from array from another table 如何在第 4 列包含与另一个表相同的 ID 的表中显示 3 列中的所有数据? - How to display all data in 3 columns from a table where the 4th column contains the same ID as another table? Mysql如何选择字段数组包含此值的行 - Mysql how to select row where field's array contains this value 从一个表中选择计数,另一个表中有一个位置 - Select count from a table with a Where on another table 从一个表中选择所有字段,其中另一个ID为ID的表中的字段等于一个字符串 - Select all fields from a table where a field in another table with an ID is equal to a string mysql查询-仅从另一个表中选择id = id,而该表中的字段=值 - mysql query - only select where id = id from another table and a field in that table = a value 从一个表中选择行,其中从另一个表中的数组中存在值 - select row from one table where value exists from array from another table 从mysql数据库中选择,其中列包含PHP - Select from mysql database where columns contains PHP
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM