我有一个来自mysql查询的奇怪结果:
如果我使用
SELECT cbe.id, cbe.user_id, cbe_profile_gender ,bud.status,cbe.avatar
FROM findme as cbe
LEFT JOIN findme_buddylist as bud ON cbe.user_id = bud.userid
WHERE cbe.user_id<>2122
AND cbe.avatar != ""
AND bud.status != "2"
我没有得到任何结果,因为表ade39_findme_buddylist是空的
但如果我删除该行:
AND bud.status != "2"
我得到的结果显示bud.status = NULL
有什么问题?
谢谢!!!
答案 0 :(得分:0)
LEFT JOIN
中 second 表的条件应该在in
子句中:
SELECT cbe.id, cbe.user_id, cbe_profile_gender ,bud.status,cbe.avatar
FROM ade39_findme cbe LEFT JOIN
ade39_findme_buddylist bud
ON cbe.user_id = bud.userid and bud.status <> 2
WHERE cbe.user_id <> 2122 AND cbe.avatar <> '';