0

我有一张名为 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

这对我不起作用。它在第二个左连接处中断。我能做些什么来解决这个问题?

4

1 回答 1

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)
于 2012-08-30T01:50:09.280 回答