Skip to content
Advertisement

MySQL – removal of duplicate results in JSON_ARRAYAGG in the presence of GROUP BY

I have query:

The result of this query duplicates the same image urls in column urlLinks:

How can I leave as a result only unique image urls?

GROUP BY cannot be removed from the request!!!

Advertisement

Answer

JSON_ARRAYAGG() does not support DISTINCT. You can SELECT DISTINCT in a subquery, and then aggregate:

Demo on DB Fiddle:

    id | urlLinks                   
-----: | :--------------------------
832781 | ["index.html", "page.html"]
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement