Subject Re: [firebird-support] expressions in "order by" clause
Author Helen Borrie
At 03:33 PM 16/03/2005 +0600, you wrote:

>Hello everybody
>
>
>
> Firebird SQL allows to use expressions in order by clause, but I haven't
>managed to make it sort by the column number which is a result of
>expression.
>
>
>
> For example:
>
>
>
> select id, name
>
> from my_table
>
> order by (1 + 1)
>
>
>
> this statement will return an unsorted set of results and
>
>
>
> select id, name
>
> from my_table
>
> order by (2)
>
>
>
>the result set will be sorted by "name" value.
>
>
>
>Is it possible to make Firebird sort by the column number which is a result
>of expression?

Yes, indeed.

select
id,
last_name || ', ' ||first_name as MemberName,
extract(year from birth_date) as BirthYear
from aTable
order by 3, 2

is perfectly valid.

In Firebird 1.5, you can also use the degree numbers to GROUP BY.

./hb