I am trying to display articles with tags. The query below works perfect.
This is my query:
SELECT
item.item_id,
item.item_title,
item.item_createdate,
GROUP_CONCAT(tag.tag_name) AS TagName
FROM
item
LEFT JOIN `item-tag` ON `item-tag`.item_id = item.item_id
LEFT JOIN tag ON tag.tag_id = `item-tag`.tag_id
/*WHERE item.item_type = 1*/
GROUP BY
item.item_id
ORDER BY
item_createdate
DESC
The problem I am having starts when I filter the results. If I want to see the results for the "Tag 1" I add the where clause:
WHERE tag.tag_name = 'Tag 1'
this removes the other tags from the GROUP_CONCAT
and I get this result:
How can I get the tagged articles and also display the additional tags for that article?



WHERE tag.tag_name LIKE '%Tag 1%'? That way, it won't matter if there are multiple tag names as long as that one exists.LIKEto work as well, are you using prepared statements?WHERE tag.tag_name IN(SELECT tag_name FROM tag)but i might have too many tags. so it is not a good option(SELECT tag_id FROM tag where tag.tag_id = item-tag.tag_id)