alapimba Posted August 29, 2014 Share Posted August 29, 2014 Hello I have a mysql table like this: id | user | car1 | 1 | fiat 5002 | 2 | vw polo3 | 2 | vw golf4 | 3 | renault clio5 | 2 | fiat panda 6 | 3 | seat ibizaFrom this table how can i get a query that the result be like: user 2 - 3 cars user 3 - 2 cars user 1 - 1 cars Thanks Quote Link to comment Share on other sites More sharing options...
Psycho Posted August 29, 2014 Share Posted August 29, 2014 (edited) SELECT user, COUNT(car) as car_count FROM table_name GROUP BY user ORDER BY car_count Edited August 29, 2014 by Psycho Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.