我想要左側加入所有主題所在的表格。我試圖做的是列出所有論壇及其子類別,並同時列出最新主題。Mysql LEFT JOIN - >獲取最新主題ID /主題標題
SELECT root.name AS root_name
, subcat.name AS subcat_name
, subcat.id AS subcat_id
, subcat.description AS subcat_description
, subcat.safe_url AS subcat_safe_url
, topics.*
FROM forum_category AS root
LEFT JOIN forum_category AS subcat ON subcat.parent_id = root.id
LEFT JOIN
(
SELECT MAX(`last_post_time`) AS aaaa, last_post_time, topic_title
, topic_id, forum_id
FROM `forum_topics`
WHERE 1
GROUP BY forum_id
) AS topics ON topics.forum_id = subcat.id
WHERE root.parent_id = 0
ORDER BY root_name, subcat_name
但我現在有點卡住了:(,它如此接近,但目前只列出各個子論壇的第一個話題,我需要的最後一個,但不知道怎麼樣。
哎呀,逗號開始行傷我的眼睛TT – roselan
呵呵我從來沒有真正想到這一點,我認爲它看起來不錯:) – John