我试图从三个表中获取值,即使一个表是空的。
因为我可以根据 following.follow_id
行是否为空来使用 if else 语句。
SELECT user.id, user.username,user.email, userdetails.profile_img, following.follow_id
FROM user
JOIN userdetails ON user.id = userdetails.user_id
JOIN following ON user.id = following.follow_id
GROUP BY user.id;
目前,如果行 following.follow_id
上有值,它只会给我值。
但是即使有一个空表,我也能够从 user_id 获得所有结果。
有什么线索吗?
最佳答案
用“LEFT JOIN”替换“JOIN”,这意味着“INNER JOIN”,应该可以解决问题。
关于mysql - JOIN 三个表,即使一个是空的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16120789/