In the hypothetical scenario where I have a couple of database tables, in a one to many relationship. I am trying to find a nice query function so that I can return each row in table A with a nested array for all the linked rows from table B.
SELECT a.id AS id,a.name as name,b.id AS b_id,b.name AS b_name FROM a,b WHERE a.id=b.eid;
will return only one result
SELECT
a.id AS id,
a.name as name,
GROUP_CONCAT(b.id) AS b_id,
GROUP_CONCAT(b.name) AS b_name
FROM a,b
WHERE a.id = b.eid;
whereas this returns what I want but I'm after an array not a string (there might be commas in b.name)
What am I missing?
You can use separator different from comma:
GROUP_CONCAT(b.name SEPARATOR ';') AS b_name