3 tables:
items(item_id, ...)
tags(item_id, tag_name)
downloads(item_id, ...)
How do I select a single item together with the number of occurrences of this item in the downloads table and all tag_name values associated with that item?
Tried:
SELECT
...,
COUNT(downloads.item_id) AS download_count,
GROUP_CONCAT(tags.tag_name SEPARATOR ":") AS tags
FROM items
LEFT JOIN tags ON items.item_id = tags.item_id
LEFT JOIN downloads ON items.item_id = downloads.item_id
WHERE items.item_id = 123
Doesn't work. Returns the tags multiple times. As many times as the occurrences of the item in the "downloads" table are.