Can you create nested WITH clauses for Common Table Expressions?

后端 未结 7 1193
花落未央
花落未央 2020-12-12 10:42
WITH y AS (
    WITH x AS (
        SELECT * FROM MyTable
    )
    SELECT * FROM x
)
SELECT * FROM y

Does something like this work? I tried it ear

7条回答
  •  甜味超标
    2020-12-12 11:26

    With does not work embedded, but it does work consecutive

    ;WITH A AS(
    ...
    ),
    B AS(
    ...
    )
    SELECT *
    FROM A
    UNION ALL
    SELECT *
    FROM B
    

    EDIT Fixed the syntax...

    Also, have a look at the following example

    SQLFiddle DEMO

提交回复
热议问题