Dynamic Order By
If I'm UNIONing 2 queries can I use a dynamic ORDER BY like this?
order by decode(sortby,'1',substr(last_name||', '||first_name||' '||mi,1,24),
**2 columns on the 2nd query are different than the 1st. and it just so happens to be what I'm trying to sort by.
I get this error "order by item must be the number SELECT-list expression".
Cause: A column alias was used in the ORDER BY clause of a SELECT statement that uses a UNION, INTERSECT, or MINUS set operator. This is not allowed. In such cases, expressions in the ORDER BY clause must be unsigned integers that designate the ordinal positions of select-list items.
Action: Change the alias in the ORDER BY clause to an unsigned integer that designates the ordinal position of the select item in question.
order by decode(sortby,'1',3,
but it gives the same error message.