json-arrayagg

Remove duplicates on MySQL JOIN query on JSON_ARRAYAGG with INNER JOIN

会有一股神秘感。 提交于 2021-01-29 05:22:57
问题 I have an app with users; the users can create bookmarks, and each bookmark can have multiple tags. So, if I'm not mistaken in the notation: user =* bookmark *=* tag Now I try to retrieve all users with a JSON array with the tags they used. I need a JSON array because I may need to retrieve the name or other data from the tags or the bookmarks: SELECT `user`.id, JSON_ARRAYAGG( JSON_OBJECT( "id", tag.id ) ) AS tags, JSON_ARRAYAGG( JSON_OBJECT( "id", bookmark.id ) ) AS bookmarks FROM tag INNER