List:General Discussion« Previous MessageNext Message »
From:Dirk Bremer \(NISC\) Date:May 12 2004 9:23pm
Subject:Re: ORDER BY Question
View as plain text  
> > select job_coop as 'Job/Coop', count(*) as Count from queue group by
> > job_coop order by Count;
>
>
> The other alternative is to omit the 'as Count' and use this query:
>
> select job_coop as 'Job/Coop', count(*)
> from queue
> group by job_coop
> order by 2;
>
> where the '2' in the 'order by' is the number of the column you are
sorting.
> (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?

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