From: Date: May 13 2004 8:25am Subject: Re: ORDER BY Question List-Archive: http://lists.mysql.com/mysql/165341 Message-Id: <40A314BC.5030709@pythagoras.se> MIME-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 8bit 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