This query does not work:
WITH a AS
(SELECT 1 AS c1)
SELECT
*
FROM
a
UNION ALL
WITH b AS
(SELECT 1 AS c1)
SELECT
*
FROM
b
Could you help, please?
Real query uses tables, but it is not essential in the example.
Many thanks
;WITH a AS
(SELECT 1 AS c1),
b AS
(SELECT 1 AS c1)
SELECT
*
FROM
a
UNION ALL
SELECT
*
FROM
b
Simple answer: you're breaking the query ;-)
Let me explain:
The result of all of these is that you want to define both of the CTEs (a & b) before the UNION query. Putting the WITH inside the UNION query breaks the UNION (since WITH is always outside of (before) a query.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With