我使用下面的SQL語句:同時連接幾個表:
SELECT reply.id, reply.content, author.username
FROM thread, reply, author
JOIN thread_reply ON thread.id = thread_reply.thread_id
JOIN reply ON thread_reply.reply_id = reply.id
JOIN author_reply ON thread.id = author_reply.thread_id
JOIN author ON author_reply.author_id = author.id
WHERE thread.id = '40'
我有follwing表:
thread_reply: thread_id, reply_id
reply: id, content, created (timestamp)
author: id, username, password_hash, salt #etc
thread: id, content, created
author_reply: author_id, reply_id
我不斷收到以下錯誤:
#1066 - Not unique table/alias: 'reply'
哦,我正在使用MySQL。
你不應該明確從'reply'選擇和'author'如果你要加入他們的行列。 – 2011-04-01 14:18:15
我的頭痛... – 2011-04-01 14:22:56
'thread_reply'和'author_reply'表有什麼意義?一個回覆可以引用多個線程嗎?一個答覆可以有多個作者嗎? – Quassnoi 2011-04-01 14:31:40