Link to home
Start Free TrialLog in
Avatar of Neil Thompson
Neil ThompsonFlag for United Kingdom of Great Britain and Northern Ireland

asked on

return a subquery as a array/comma seperated list within the row

Hi all

I'm struggling with a MySQL query where I would like to pull back an array of all the peoples ID's that a person has favorited but I keep getting "Error Code: 1242. Subquery returns more than 1 row"

Here's the basic SQL, it grabs the [usr_id] and [usr_username] from the [users] table and then I would like a comma separated list of all that persons [uf_favourited_user_id] from the [user_favourites] table

Example:
User generated image
SELECT usr_id, usr_username, (SELECT uf_favourited_user_id FROM user_favourites WHERE uf_user_id = 19) AS favourites
FROM users 
ORDER BY usr_date_registered
LIMIT 50

Open in new window

Avatar of Dorababu M
Dorababu M
Flag of India image

ASKER CERTIFIED SOLUTION
Avatar of OMC2000
OMC2000
Flag of Russian Federation image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Neil Thompson

ASKER

Perfect, thank you.

I had tried that but obviously messed up the syntax along the line and gave up after it kept failing.