Вот пример
INSERT
INTO values (a,b) //more values
WITH table AS
(
SELECT *
FROM table1
)
WITH table2 AS //from more tables
(
SELECT *
FROM table_2
)
SELECT t.value as a, t2.value as b
FROM table t
JOIN table2 t2 on t.value = t2.value //some join
WHERE t.value = 'X' //other stuff