除了一些列之外如何进行LEFT OUTER JOIN?

时间:2017-01-31 09:26:10

标签: mysql sql wampserver

我有3张桌子:

首先"安置" enter image description here

第二个" user_info"

enter image description here

第三个" user_placements"

enter image description here

我想通过用户信息获取所有展示位置数据

enter image description here

怎么做?

我试过这个,但结果并不是我的预期:

SELECT *, user_placements.id AS user_placements_id, placement.id AS placement_id
FROM placement
LEFT OUTER JOIN user_placements ON placement.id = user_placements.id_placement

2 个答案:

答案 0 :(得分:1)

您需要再添加一个用户信息

SELECT placement.*,user_info.id as user_info_id,user_info.name as user_name,user_info.mobile as user_mobile
 FROM placement LEFT OUTER JOIN user_placements ON placement.id = user_placements.id_placement
    LEFT OUTER JOIN user_info ON user_info.id = user_placements.id_user

答案 1 :(得分:1)

您缺少第二次加入:

SELECT *
FROM placement AS p
JOIN user_placements AS up ON p.id = up.id_placement
JOIN user_info AS u ON up.id_user = u.id

将通配符替换为您想要的数据。 您当然会通过此查询获得重复数据。