我有3张桌子:
第二个" user_info"
第三个" user_placements"
我想通过用户信息获取所有展示位置数据
怎么做?
我试过这个,但结果并不是我的预期:
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
答案 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
将通配符替换为您想要的数据。 您当然会通过此查询获得重复数据。