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:
sql required results
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

LVL 3
Neil ThompsonSenior Systems DeveloperAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dorababu MSenior Software EngineerCommented:
0
OMC2000Commented:
try this:

SELECT usr_id, usr_username, GROUP_CONCAT(uf_favourited_user_id SEPARATOR ',') AS favourites
FROM users join user_favourites  on usr_id = uf_user_id
WHERE uf_user_id = 19
GROUP BY usr_id, usr_username, usr_date_registered 
ORDER BY usr_date_registered

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Neil ThompsonSenior Systems DeveloperAuthor Commented:
Perfect, thank you.

I had tried that but obviously messed up the syntax along the line and gave up after it kept failing.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
SQL

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.