Vishu238
Vishu238

Reputation: 673

mysql query to fetch data in comma separated form

I have a table (user table ) in which data is stored as below

| name  |  address  |
|  A    |  x        |
|  A    |  y        |
|  C    |  z        |

and i want output like below

    | name  |  address  |
    |  A    |  x ,y     |
    |  C    |  z        |

I need to show these values in a user table(html view) in comma separated value(eg. address1,address2) Please help me to code it in php I am using php in backend.

Upvotes: 0

Views: 593

Answers (1)

Abhik Chakraborty
Abhik Chakraborty

Reputation: 44844

You can use group_concat as

select
name,
group_concat(address) as address
from user
group by name

Upvotes: 1

Related Questions