What I want to do is merge the rows which have same values but in different column & Show them in a single row
I Tried to use the JSON_ARRAYAGG() but didn't get the results in my way
User Data
Here secondary user is the reference of primary_user
id | username | secondary_user | code |
---|---|---|---|
1 | max_max | null | 1356 |
2 | jac_jac | 1 | 1111 |
3 | leo_leo | null | 2222 |
4 | bob_bob | 3 | 4444 |
Result I want
id | username | secondary_user | code | secondary_users |
---|---|---|---|---|
1 | max_max | null | 1356 | [{"jac_jac", "1111"}] |
3 | leo_leo | null | 2222 | [{"bob_bob", "4444"}] |