I have a query that returns a list of items that an owner has:
WITH all_items
AS
(
SELECT owner.id AS owner,
item.title,
item.importance
FROM owner
JOIN item
ON item.owner_id = owner.id)
SELECT owner.id,
group_concat(DISTINCT item.title ORDER BY item.importance SEPARATOR ',')
FROM owner
JOIN all_items
ON all_items.owner = owner.id
I need to limit the group_concat to max of 6 items. I can't do LIMIT in all_items because it returns only the top 6 items, regardless of who the owner is. How do I do this?