List:General Discussion« Previous MessageNext Message »
From:Paul DuBois Date:September 14 2002 8:02pm
Subject:RE: Re-sequencing a query result set with MYSQL
View as plain text  
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 
Count(Value)
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
>by Value";
>
>-----Original Message-----
>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:
>>Hi Folks,
>>
>>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
>results
>>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.
>>
>>Thanks,
>  >                 Dhar.

Thread
data normalization questionspeters6 Sep
  • Re: data normalization questionArthur Fuller14 Sep
    • Re-sequencing a query result set with MYSQLDharmendra sawh14 Sep
      • Re: Re-sequencing a query result set with MYSQLPaul DuBois14 Sep
        • RE: Re-sequencing a query result set with MYSQLDharmendra sawh14 Sep
          • RE: Re-sequencing a query result set with MYSQLPaul DuBois15 Sep
            • Format can I Do this in MYSQLBryan15 Sep
              • Re: Format can I Do this in MYSQLPaul DuBois15 Sep
                • RE: Format can I Do this in MYSQLBryan15 Sep
              • Re: Format can I Do this in MYSQLJenny Barton16 Sep
      • Re: Re-sequencing a query result set with MYSQLpeter.brawley15 Sep
  • Re: data normalization questionBobJ14 Sep