At 13:42 -0600 9/14/02, Dharmendra sawh wrote:
>here is the query. I was under the impression that a group by overrode the
>sequencing of an order by. Correct?
Not quite. GROUP BY produces a sort order, so that if it's the order you
want, you don't need an explicit ORDER BY. (This is not true of some other
database engines, by the way). But if the order produced by GROUP BY isn't
the order you want, you can override it with an explicit ORDER BY.
So just order on Count(Value) and you should get the results in the order
you want. If your version of MySQL is older than 3.23.2, alias the
column and use the alias name in the ORDER BY clause. (You can't use
ORDER BY with expressions prior to 3.23.2.)
>$query = "select Value, Count(Value) from TABLE where Item = '$Item' group
>From: Paul DuBois [mailto:paul@stripped]
>Sent: Saturday, September 14, 2002 1:39 PM
>To: dsawh1@stripped; mysql@stripped
>Subject: Re: Re-sequencing a query result set with MYSQL
>At 13:27 -0600 9/14/02, Dharmendra sawh wrote:
>>Here is my situation:
>>Me query for my MYSQl table is using count on a specific column and also
>>using the group by clause to get the number of occurrences of the group by
>>column in the table. After I get the result set I wan to order the
>>by the count in descending order.
>With an ORDER BY clause. But that answer seems so obvious that I suspect
>there's something unusual about your query that this doesn't work?
>Maybe you can show the query.
>>Does anyone know how to do this? I also would like to do this to reorder
>>the display on the page without re-reading the DB.
> > Dhar.