This is a basic example of how to use CTE (common table expression)

with TableName1 as
(query 1) ,
TableName2 as 
(query 2)

select TableName1.color, TableName2.displaytxt
from TableName1 join TableName2
on TableName1.id = TableName2.id
join OtherRealTable
on TableName1.id = OtherRealTable.id

You can also specify column names as follow:

with TableName1 (pay, ave_pay, tot_pay) as
(select a, b, c from d)
select pay, ave_pay, tot_pay from TableName1


What's your thoughts on this?


Protected by WP Anti Spam