Click to See Complete Forum and Search --> : order by/union


tiger66
08-20-2003, 11:19 AM
Hi I am just wondering can I use order by and union all together?

When I try the statement below
select ......... order by ID
union all
select ......... order by ID

I get an invalid SQL statement error message

If I can't use order by/union together, are there any workaround?

I am usering oracle 11i

Thanks

karlmcauley
08-21-2003, 03:24 AM
Just have the order by after the union:My example:

select fes_per_person_code, uio_occurrence_code
from registration_units
where uio_occurrence_code like '02/03%'

union

select fes_per_person_code, uio_occurrence_code
from registration_units
where uio_occurrence_code like '03/04%'

order by fes_per_person_code

Obviously the order by has to have the same fields in both select statements, but the above will return students in 0203 and 0304

Hope this helps