objectWithoutClass
objectWithoutClass

Reputation: 1679

sql with clause within a with clause

can i do something like this :

with t as 
    (
        with tt as
            ( 
                 select * from table 
            )
        SELECT * FROM tt
    )
select * from t

i willing to perform some logic on output of inner with clause & than again do some operations on output of the outer with clause.

any help will be appreciated ...
Thanks

note :- its just some simplified query that will resolve my problem in my actual query, which have nested with clause

Upvotes: 13

Views: 31238

Answers (2)

Giannis Paraskevopoulos
Giannis Paraskevopoulos

Reputation: 18421

You can do something like this:

with t as 
(
    select * from table
),
tt as
( 
     select * from t
)
select * from tt 

Upvotes: 40

marc_s
marc_s

Reputation: 755421

No, you cannot nest CTE (Common Table Expression) but you can chain them:

with t as 
(
    select * from table 
),
tt as
( 
    select * from t
)
SELECT * FROM tt

Upvotes: 14

Related Questions