List:General Discussion« Previous MessageNext Message »
From:Johan Hook Date:May 13 2004 8:25am
Subject:Re: ORDER BY Question
View as plain text  
Hi Dirk,
from the excellent on-line manual:

http://dev.mysql.com/doc/mysql/en/SELECT.html

Columns selected for output can be referred to in ORDER BY and GROUP BY clauses 
using column names, column aliases, or column positions. Column positions are 
integers and begin with 1:

mysql> SELECT college, region, seed FROM tournament
     ->     ORDER BY region, seed;
mysql> SELECT college, region AS r, seed AS s FROM tournament
     ->     ORDER BY r, s;
mysql> SELECT college, region, seed FROM tournament
     ->     ORDER BY 2, 3;

/Johan

Dirk Bremer (NISC) wrote:

> 
>>(The count(*) expression is the second column of the result set so you
>>replace it with a 2). This saves you from having to use an 'As' expression
>>for 'count(*)' although it makes the query less clear too. (It won't be
>>apparent to some people what the effect of the '2' in the 'order by' is.)
>>
>>Rhino
> 
> 
> Thanks for all of the suggestions, the 'order by count' worked like a charm.
> Concerning Rhino's suggestion quoted above, it this method of using numbers
> to represent the columns documented anywhere?
> 
> 


-- 
Johan Höök, Pythagoras Engineering Group
		- MailTo:johan.hook@stripped
		- http://www.pythagoras.se
Pythagoras AB, Stormbyv. 2-4, SE-163 55 SPÅNGA, Sweden
Phone: +46 8 760 00 10 Fax: +46 8 761 22 77


Thread
ORDER BY QuestionDirk Bremer \(NISC\)12 May
  • Re: ORDER BY QuestionMichael Kruckenberg12 May
  • Re: ORDER BY Question(Johan Hook)12 May
  • Re: ORDER BY QuestionRhino12 May
  • Re: ORDER BY QuestionDirk Bremer \(NISC\)12 May
    • Re: ORDER BY Question(Johan Hook)13 May