[quoted text, click to view] Anith Sen wrote:
> Aaron,
>
> Since carrier is just an alias for the column, the statement will not
> compile using CASE having a reused alias. One workaround is to make the
> whole UNION query as derived table construct & apply the ORDER BY on the
> outer query.
>
> SELECT *
> FROM ( < union query > ) T
> ORDER BY CASE WHEN carrier = 'ALL' THEN 1 ELSE 2 END ;
>
Both the sort and your query worked fine:
***********************************************************************
select * from (select 'ALL' as carrier,'ALL' as carrierCode union select
name,carrier_code from carrier where default_class is not null) T
ORDER BY CASE WHEN carrier = 'ALL' THEN 1 ELSE 2 END
*************************************************************************
Why does the T have to follow derived table? I noticed (when I
accidently left it off) that it didn't work. Worked fine when I added it.
Also, which would be more efficient - the sort or the derived table - or
would it matters. Is there a way to tell?
Thanks,
Tom.
[quoted text, click to view] >