Hello, Im trying to create a query to get the most popular.. heres an example. I have a table called items. I have a column called colors. I successfully did a row count echoing out: 2 - red 3 - green 6 - black 1 - white How can i get the largest value? I then took it one step further and ORDER BY ASC so essentially this is what i have SELECT items, COUNT(items) FROM colors GROUP BY color ORDER BY color ASC" so right now im listing out the colors, and its tallying them. How can I get it to give me the largest tally? Im kinda new to this.. so.. all help is appreciated. thanks!!
Maybe something like: SELECT items, COUNT(items) AS item_count FROM colors GROUP BY color ORDER BY item_count DESC
hmm I am having a little trouble with your query string jestep. Im getting confused with the AS item_count part, can you explain that a little bit please? Thanks!
All "AS item_count" does is give the count a column name that you can reference in the order by clause. He's using it to sort the list from highest to lowest (descending).
What jesteps query does is the following: SELECT items, COUNT(items) FROM colors GROUP BY color ORDER BY COUNT(items) DESC By using a named column in jesteps example the query becomes a bit easier to read and you are reusing your count(items) code so it becomes a bit more maintenance friendly.