I've tried very hard to have a normalized database and currently have three tables like so -
- content (c)
- content_tags (ct)
- tags (t)
What I'm trying to do here is select some rows and return them with all the tags that are associated with it. At the moment, it only returns one tag for some reason.
Here is the code I'm using:
SELECT *,
GROUP_CONCAT(t.tag) AS tags
FROM content AS c
LEFT JOIN category AS ca ON c.cid = ca.cid
LEFT JOIN contenttags AS ct ON c.smid = ct.smid
LEFT JOIN tags AS t ON ct.tid = t.tid
LEFT JOIN users AS u ON c.uid = u.uid
WHERE (t.tag IN ('tag1', 'tag2', 'tag3'))
GROUP BY c.smid
It returns something like this:
- cid
- content
- url
- tag (but only one instead of multiple)