我希望使用以下结构连接多个表:
Users (userId, name)
Emoticons (emoticonId, name)
UnlockedEmoticons (userId, emoticonId, name)
对于每个项目,我希望显示用户是否解锁了特定的图释,如:
1(emoticonId), emoticonA(name), unlocked (userId IS NOT NULL) AS has?,
2(emoticonId), emoticonB(name), locked (userId IS NOT NULL) AS has?
问题是,如果解锁图标中没有userid,我会得到空结果。
SELECT e.*, (ue.id IS NOT NULL) AS `has`
FROM UnlockedEmoticons ue RIGHT JOIN emoticons e ON ue.emoticonId = e.emoticonId
LEFT JOIN users u ON u.id = ue.userId
WHERE uk.userId = 33
我试图更改join语句的顺序,但没有效果。有办法做到这一点吗?
我正在使用MySQL5.7
1条答案
按热度按时间uxh89sit1#
诀窍是在on语句之后包含和:
并删除where语句。:)