I have a query where the individual selects are pulling the most recent result from the table. So I'm having the select order by id desc, so the most recent is top, then using a rownum to just show the top number. Each select is a different place that I want the most recent result.
However, the issue I'm running into is the order by can't be used in a select statement for the union all.
select 'MUHC' as org,
aa,
messagetime
from buffer_messages
where aa = 'place1'
and rownum = 1
order by id desc
union all
select 'MUHC' as org,
aa,
messagetime
from buffer_messages
where aa = 'place2'
and rownum = 1
order by id desc;
The each select has to have the order by, else it won't pull the most recent version. Any idea's of a different way to do this entirely, or a way to do this with the union all that would get me the desired result?