Skip to content
Advertisement

Query ORDER with UNION

I have to do punt an “*” in a list of dates, like this:

*
1/1/2021
2/1/2021
3/1/2021
...

So, with my low knowledge, I created something like this code:

SELECT Disciplines_Date.Date_Modification
FROM Disciplines_Date
ORDER BY Date_Modification DESC;
UNION 
SELECT UnionTable.ABC 
FROM UnionTable;

where “*” is present in the table Union. But, the command ORDER doesn’t work and I’ve a sort system just by number, like the follow:

*
9/01/2021
3/01/2021
12/01/2021
21/01/2021

How can avoid this? Thanks for the help

Advertisement

Answer

Thanks a lot to all, here some feedback:

select * from ( SubQuery1 UNION Subquery 2) ) as ANYname order by

This is working without “AS” and ORDER. If I put “AS name” and ORDER BY, the order will not work.

or

    select abc from 
(SELECT 1 as sl, UnionTable.ABC 
FROM UnionTable
UNION
SELECT 2 as sl, Disciplines_Date.Date_Modification
FROM Disciplines_Date  ORDER BY sl, abc desc)

Both working only in ASC Mode not DESC. Anyway, thanks a lot to everybody.

User contributions licensed under: CC BY-SA
9 People found this is helpful
Advertisement