Subquery and results in string format in mysql?

i have 3 tables :users,message,receiver
-----------------------------------------------------------------------------------
users
user_id,name
-----------------------------------------------------------------------------------
messages
message_id,user_id,message
-----------------------------------------------------------------------------------
receiver
message_id,sender_id,receiver_id
-----------------------------------------------------------------------------------

i have sent_messages.php

i have to show results in below

comma_seperated_names(to whom i send message)                                                  message
---------------------                                                                                                      -----------------
Adam,Joe,Mary,John                                                                                                         Hello

How can i do only one query

my query = select (select name from users u,receiver r where u.user_id=r.receiver_id and r.message_id=m.message_id) as comma_separated_names,m.message from messages m where m.user_id='10'

subquery returns more than 1 result , i want to subquery result be in one result and comma separated
phparmyAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
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.

UmeshSenior Principal Technical Support EngineerCommented:
Try this...


select GROUP_CONCAT(DISTINCT name SEPARATOR ',')  from users u,receiver r where u.user_id=r.receiver_id and r.message_id=m.message_id) as comma_separated_names,m.message from messages m where m.user_id='10'

Open in new window

UmeshSenior Principal Technical Support EngineerCommented:
Opps.... Pls try this..
select (select GROUP_CONCAT(DISTINCT name SEPARATOR ',') from users u,receiver r where u.user_id=r.receiver_id and r.message_id=m.message_id) as comma_separated_names,m.message from messages m where m.user_id='10'

Open in new window

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
phparmyAuthor Commented:
you have to remove DISTINCT then it works thanks.
phparmyAuthor Commented:
You have to remove distinct
UmeshSenior Principal Technical Support EngineerCommented:

Thanks for the points!
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
PHP

From novice to tech pro — start learning today.