我有一个名为meeting的表,还有一个名为meeting_permissions的表。后者存储用户参加任何特定会议的内容。我还有其他表格:注释,讨论,结论和主题,用于存储该会议成绩单的特定项目。我想做的是获得特定用户参与的所有会议,以及所有相关的注释,讨论,结论和主题。这就是我想出的:
SELECT * FROM meeting WHERE id IN
(SELECT meeting_id FROM meeting_permissions WHERE user_id = $user)
LEFT JOIN conclusion ON meeting.id = conclusion.meeting_id
LEFT JOIN discussion ON meeting.id = discussion.meeting_id
LEFT JOIN note ON meeting.id = note.meeting_id
LEFT JOIN topic ON meeting.id = topic.meeting_id
这对我不起作用。它打破了第二个左连接。我该怎么做才能解决这个问题?
答案 0 :(得分:1)
您加入了您的子选择而不是主会议桌:
SELECT
meeting.*,
conclusion.*
discussion.*,
note.*,
topic.*
FROM meeting
LEFT JOIN conclusion ON meeting.id = conclusion.meeting_id
LEFT JOIN discussion ON meeting.id = discussion.meeting_id
LEFT JOIN note ON meeting.id = note.meeting_id
LEFT JOIN topic ON meeting.id = topic.meeting_id
WHERE meeting.id IN
(SELECT mp.meeting_id FROM meeting_permissions mp WHERE mp.user_id = $user)