Hello everybody,
I am using a Union Query to combine the results of 2 CTE's into a single data set. My query is working and I am getting the results that I expect. The only thing is that I would like to do an ORDER BY on my date column. Here is the code I have:
WITH CTE_Orders
AS
(
SELECT
o.Order_Number,
o.Order_Region,
o.Processed_Date
FROM orders o
),
CTE_Sales
AS
(
SELECT
s.Sales_Number,
s.Sales_Region,
s.Processed_Date
FROM Sales s
)
SELECT o.Order_Number, o.Order_Region, o.Processed_Date
FROM CTE_Orders o
UNION
ALL
SELECT s.Sales_Number, s.Sales_Region, s.Processed_Date
FROM CTE_Sales s
I know that I can't use Order BY in the CTE.
Is there a way of sorting the results of my query in date order?
I don't have much experience with union queries so any help would be much appreciated.
Many Thanks
Vinnie