[英]Join multiple table if there are multiple id store in a row
I have three table in database that are skill,job_post and experience. 我在数据库中有三个表,即技能,job_post和经验。 Here, I have to join these all table.
在这里,我必须加入这些所有表格。
Here I have job_post table like this : 这里我有这样的job_post表:
Skill table looks like : 技能表看起来像:
And experience table looks like 体验表看起来像
Now, I have to join above table.Here I have join job_post and experience table. 现在,我必须加入上面的表。我已经加入了job_post和经验表。
So I have written join query like : 所以我写了连接查询,如:
"select * from job_post as jp
join experience as e on e.exp_id = jp.exp_id
where jp.emp_id in (".$ids.")"
But, here multiple skill_id are inserted in job_post table so how can I join job_post table to skill table? 但是,这里有多个skill_id插入job_post表中,那么如何将job_post表连接到技能表呢?
Note : What I have tried is that I have write above join query then write foreach loop of that result and take skill ids from the job_post table.Then write query that match with the skill table and print skill. 注意:我尝试的是我已经在上面写了连接查询然后编写该结果的foreach循环并从job_post表中获取技巧ID。然后编写与技能表和打印技能匹配的查询。
But is there any way to write query instead of doing these ? 但有没有办法编写查询而不是这些?
You can use MySQL find_in_set
and group_concat
to do the third join : 您可以使用MySQL
find_in_set
和group_concat
来执行第三次连接:
select jp.*,e.*,group_concat(s.skill)
from job_post jp
join experience e on e.exp_id = jp.exp_id
join skill s ON(FIND_IN_SET(s.skill_id, jp.skill) > 0)
where jp.emp_id in (".$ids.")
GROUP BY jp.job_id,jp.exp_id
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.