SELECT submissions.created_at, guests.accepted
FROM submission
INNER JOIN guests
ON guests.event_id = 1
ORDER BY submissions.created_at ASC;
目前此查询需要很长时间才能运行(甚至可能无法返回所有内容)。 我想要完成的任务:
抓取字段submissions.created at和guests.accepted(两者通过submission_id链接) 给定某个event_id(例如事件1)。
我的查询有什么问题?
答案 0 :(得分:4)
您忘记在查询中提供JOIN条件。试试这个:
SELECT submissions.created_at, guests.accepted
FROM submission s
INNER JOIN guests g on g.event_id = s.submissions_id
where guests.event_id = 1
ORDER BY submissions.created_at ASC;
答案 1 :(得分:1)
SELECT submissions.created_at, guests.accepted
FROM submission
INNER JOIN guests
ON guests.(column to match against) = submissions.(column to match on)
where guests.event_id=1
ORDER BY submissions.created_at ASC;
正如这里的许多其他人已经说过的那样,你的加入有点蠢。它正在尝试将来宾表中匹配的一行与提交列中的每一行连接起来。
答案 2 :(得分:0)
您需要像这样进行加入:
Inner join guest on guest.event_id = submissions_id
where guest.event_id = 1
当你加入时,你需要加入来自不同表的两列(大多数时候是id列) 您可以阅读MySQL example以获取更多解释。以下是MySQL reference manual
的链接