This works but it doesn’t keep the order of the elements. When I run ORDER BY FIELD solely it behaves as expected, but not here. Any ideas how to fix it.
SELECT GROUP_CONCAT(JSON_ARRAY((SELECT name ORDER BY FIELD(position, CONCAT(',', position, ',') )))) AS obj
FROM tags
WHERE tag_id IN (1, 2, 3)
The tag table structure is:
tag_id PK
name
position