I am searching "FOR JSON PATH" (SQL Server) equivalent in MySQL and came across the following link - stackoverflow question
The most rated solution works perfectly but is it possible to provide the columns and values dynamically? I have over 20 columns and adding each key-value pair manually is hectic & not easy to maintain.
SQL Server Query-
SELECT u.user_id, u.first_name,(
SELECT f.*
FROM files f
WHERE f.is_active = 1 AND f.user_id = u.user_id
FOR JSON PATH) as files
FROM users u
WHERE u.user_id = 1
The output from the above query and the 1 generated using JSON_ARRAYAGG(JSON_OBJECT()) function is the same.