Neil Thompson
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:
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:
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
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Perfect, thank you.
I had tried that but obviously messed up the syntax along the line and gave up after it kept failing.
I had tried that but obviously messed up the syntax along the line and gave up after it kept failing.
http://dev.mysql.com/doc/refman/5.1/en/string-functions.html#function_find-in-set