Sub Query Order By – Union Order By – Sort

To use Order By in a Sub Query or Union Query, where you want to order two table ids in ascending or descending order, following could be the solution for sorting your results.

Sort Results – Order By In Union – Order By In Sub Query

To sort and order your query results in sub query or union, you may have to use the following type of query, to get your desired results sorting:

SELECT * FROM
(
SELECT id, name, address FROM tbl1
UNION ALL
SELECT id, name, address FROM tbl2
)
AS a
ORDER BY a.id;

Uncategorised

Leave a Reply

Your email address will not be published. Required fields are marked *