I'm building a StackOverflow mini-clone. I have the following database relations:
questions
- question_id
- title
tags
- tag_id
- name
question_tags
- foreign key tag_id
- foreign key question_id
Supposedly, this is the proper way to organize a tagging system.
Now, how could I query all questions with the tag 'java', and at the same time, when listing those questions, also show all the tags that each question is associated with?
I feel like denormalizing and putting an extra field into questions, say tag_string, which would have a listing of tags as CSV, so I can have a simpler query for this case.
Of course, it is not a problem when showing a single question:
SELECT * FROM questions LEFT OUTER JOIN question_tags USING(question_id)
LEFT OUTER JOIN tags USING(tag_id)
WHERE question_id = 42;