I have an Sql query that is the union of three queries, for example :
You would normally do this by including a column specifying the query and ordering by that:
select . . . from ((select q.*, 1 as ordering from (<query1>) q) union all (select q.*, 2 as ordering from (<query2>) q) union all (select q.*, 3 as ordering from (<query3>) q) ) q order by ordering;
Note: This replaces the
union all, so duplicates are not removed.