Radoslav Radoslav - 4 months ago 7
SQL Question

I have no Idea how to describe it, but

I have a mysql table with following data: user, userstat

SELECT * FROM table ORDER BY user


Result of my query looks like:

USER USERSTAT

usr1 1
usr1 2
usr1 3

usr2 1
usr2 2
usr2 3


I would like to do it this way:

USER USERSTAT

usr1 1
2
3

usr2 1
2
3


is there any possibility?

(working in PHP) Thank you.

Answer

Use following sql query

select user,GROUP_CONCAT(userstat) as userstats from  table  group by user.
Comments