mysql使用链接表从两个表中获取结果

时间:2016-06-19 07:19:26

标签: php mysql

请问各位大家如何执行正确的查询以获得“输出”,如下图所示 如果你能帮助我,我真的很感激你们 提前致谢。

enter image description here

1 个答案:

答案 0 :(得分:1)

通常你会这样做一个JOIN:

SELECT rt.room_name AS Room, at.amenities_name AS Amenities FROM
link_table AS lt JOIN room_table AS rt ON lt.room_id = rt.room_id
JOIN amenities_table AS at ON lt.amenities_id = at.amenities_id;

得到这样的结果:

Room       Amenities
--------------------
Room 101   WIFI
Room 101   A/C
...        ...
Room 102   A/C
...        ...