First I am newbie to php and mysql. I am trying to do read some data from a table in most efficient way possible.
Here is a simple example of an table. Two columns are color and username
The array I want to get out of query is like this
Normally, I would make
1. Select query for distinct color and get array fo colors and save in array A
2. Another query to get count for each color and save in array B
3. Then sort the array using array_multisort so that colors with the most username records is on the top (in above example order would be red,blue,yellow)
Can you get all three steps done in one query? If not, can you get step one and step two done in one query so array will be like (color,# of users) for all distinct colors.