Title is bad, Hope the example will clarify this.
I have an event. Event has tags.
(Simplified) I show the event thus:
SELECT
*.event,
GROUP_CONCAT(tag.name)
FROM event
JOIN tag
ON event.tag_id = tag.id
GROUP BY event.id
Say I want to filter it, and fetch only those events which have tag.id =2
But still show the entire event, with all it’s tags.
SELECT
*.event,
GROUP_CONCAT(tag.name)
FROM event
JOIN tag
ON event.tag_id = tag.id
WHERE tag.id = 2
GROUP BY event.id
This won’t work, as it will show the event details correctly, but only the tag of which it’s is 2
I am pretty sure I am missing something very simple, what is it ? 🙂
Solutions I am aware of:
- Fetch tags at a later time, after I loaded the event details.
- Use inner query instead of the
GROUP_CONCAT(tag.name)to fetch current event tags
Both seems “not clean” to me.
or: