How can you select question_id
and tag
s for a question when one of the tags is known?
I am building a tag-search which searches questions by one tag such that the result shows the question and its tags including the one which was used in the search.
I use the same tables as in this question. They are
Tables
questions | tags
-------------------|-----------------
question_id | tag
title | question_id
was_sent_at_time |
The query
SELECT question_id, tag
FROM tags
WHERE question_id IN
(
SELECT question_id
FROM questions
ORDER BY was_sent_at_time
DESC LIMIT 50
)
AND tag = $1; // Problem here
The problem with this query is that it does not show other tags assigned to the question. It may be possible to get the question_id and tags if there exists a given tag.