我有以下表格:使用更簡單的方法加入
作者:
ID的用戶名郵箱密碼鹽 email_salt email_verified IP_ADDRESS
Author_threads:
thread_id,author_id
主題:
ID,標題,內容,創造
標籤:
ID,名稱
Thread_tags:
tad_id,THREAD_ID
我想選擇最新的30個線程,它們的作者和他們所有的標籤。這是我使用的SQL語句:
SELECT thread.title, thread.id as thread_id,
thread.content, author.username, author.id as author_id,
GROUP_CONCAT(DISTINCT tag.name ORDER BY tag.name DESC SEPARATOR ',') AS tags
FROM thread
JOIN thread_tags ON thread.id = thread_tags.thread_id
JOIN tag ON thread_tags.tag_id = tag.id
JOIN author_threads ON thread.id = author_threads.thread_id
JOIN author ON author_threads.author_id = author.id
GROUP BY thread.id DESC
LIMIT 0, 30
有沒有更簡單的方法來做到這一點?
這是MySQL嗎?您應該包含數據庫類型標記。 – JeffO 2011-03-16 15:32:09
是的,很抱歉,這是MySQL – 2011-03-16 15:45:27