What is causing the error "column reference "col_1" is ambiguous?
WITH cte1 AS
(
SELECT col_1, col_4
from table_1
),
cte2 AS
(
SELECT two.col_1, two.col_5, three.col_6
from table_2 as two
left join table_3 as three
on two.col_1 = three.col_1
),
cte3 AS
(
SELECT col_1, col_10
from table_4
)
SELECT cte1.col_1, cte1.col_4,
cte2.col_1, cte2.col_5, cte2.col_6,
cte3.col_1, cte3.col_10
FROM cte1
left join cte2 on cte1.col_1 = cte2.col_6
left join cte3 on cte1.col_1 = cte3.col_10
;
I suspect cte2 is causing the ambiguous column name issue in the final outer query?