I am in the process of simplifying a complicated select statement, so thought I would use common table expressions.
Declaring a single cte works fine.
WI
I think it should be something like:
WITH
cte1 as (SELECT * from cdr.Location),
cte2 as (SELECT * from cdr.Location)
select * from cte1 union select * from cte2
Basically, WITH
is just a clause here, and like the other clauses that take lists, "," is the appropriate delimiter.
Above mentioned answer is right:
WITH
cte1 as (SELECT * from cdr.Location),
cte2 as (SELECT * from cdr.Location)
select * from cte1 union select * from cte2
Aditionally, You can also query from cte1 in cte2 :
WITH
cte1 as (SELECT * from cdr.Location),
cte2 as (SELECT * from cte1 where val1 = val2)
select * from cte1 union select * from cte2
val1,val2
are just asumptions for expressions..
Hope this blog will also help : http://iamfixed.blogspot.de/2017/11/common-table-expression-in-sql-with.html