I'm in the early stages of my database design so nothing is final yet, and I'm using the "TOXI" 3-table design for my threads which have optional tags, but I can't help but feel that the joining is not really necessary and perhaps I need to just rely on a simple tags column in my posts
table where I can just store a varchar of something like <tag>, <secondTag>
.
So to recap:
- is it worth the trouble of the extra left joins on the 2 tag tables instead of just having a tag column in my
posts
table. - is there a way I can optimize my query?
Schema:
posts
---------
post_id post_name
1 test
post_tags
---------
tag_id tag_name
1 mma
2 ufc
posts_tags_map
--------
map_id post_id tags_id
1 1 1
2 1 2
Current query:
SELECT
posts.*,
GROUP_CONCAT( post_tags.tag_name order by post_tags.tag_name ) AS tags
FROM posts
LEFT JOIN posts_tags_map
ON posts_tags_map.post_id = posts.post_id
LEFT JOIN post_tags
ON posts_tags_map.tags_id = posts_tags.tag_id
WHERE posts.post_id = 1
GROUP BY post_id
Result:
post_id post_name tags
1 test mma, ufc
*IF* there are tags