【发布时间】:2011-06-04 12:03:35
【问题描述】:
我有一个与此问题相似的表结构接受答案:Recommended SQL database design for tags or tagging
我的除外
thread, thread_tags and tags
使用下面的SQL命令我可以得到每个线程关联的一个标签,我怎样才能得到每个线程关联的所有标签?
SELECT
thread.id AS t_id,
thread.title,
thread.content,
author.username,
author.id AS a_id
FROM thread
INNER JOIN author
ON author_id = author.id
INNER JOIN thread_tags
ON thread_id = thread.id
INNER JOIN tags
ON tag_id = tags.id
ORDER BY thread.created DESC
【问题讨论】:
-
什么是
author_id?你应该把表名放在任何地方,或者更好的是,一个缩短的名字(即FROM thread TH INNER JOIN author A on TH.author_id = A.id