我有三张表,员工,技能和技术 tables
=====================
| employe |
=====================
|id_employe |
|name |
|id_skill |
=====================
| skills |
=====================
|id_skill |
|Id_technologie |
=====================
=====================
| technologies |
=====================
|id_technologie |
|name |
=====================
在每张桌子中我都有这些 records
employe
=============================
|id_employe|name |id_skill |
=============================
|1 |jhon |1 |
|2 |tom |2 |
skill
=============================
|id_skill | id_technologie |
=============================
|1 | 1 |
|1 | 2 |
|2 | 1 |
|2 | 4 |
technologies
============================
|id_technologie| name |
============================
|1 | PHP |
|2 | Java |
|3 | Python |
|4 | C |
我想得到一个结果 this
=============================================
id_employe| name | id_skill| name | name
=============================================
1 | jhon | 1 | PHP | Java
我试图这样做,但结果不是我的预期
function listar(){
$users = DB::table('employe')
->join('skills', 'skills.id_skill', '=', 'employe.id_skill')
->join('technologies', 'technologies.id_technologie', '=', 'skills.id_technologie')
->where('skills.id_skill', '=', 1)
->get();
return response()->json($users,200);
}
答案 0 :(得分:0)
原件:
您确定输入了正确的列吗?
我在相片中看到的是id_skills
和id_technologie
。
DB::table('employe')
->join('skills', 'skills.id_skills', '=', 'employe.id_skills')
->join('technologies', 'technologies.id_technologie', '=', 'skills.id_technologie')
->where('skills.id_skills', 1)
->get();
新:
你想在1行中获得2个结果。
并通过1 Query SQL。
您不知道有多少technologie
一个skills
相关。
我想解决的方法是首先选择skills
。
然后找到technologie
,您可以将其命名为Name1
,Name2
等。
请原谅我英语不好。