WITH test(id, not_id) AS ( SELECT * FROM (VALUES (1,1), (3,4)) AS t ),
test2(id1) AS ( SELECT * FROM (VALUES (2), (3) ) AS t ) -- SELECT not_id FROM test2 -- ERROR column "not_id" does not exist SELECT * FROM test WHEREidIN ( SELECT not_id FROM test2 ); -- <-- not_id selected from test table no ERROR, result is: 1,1
You've introduced a correlated subquery due to insufficient use of table qualifiers on column names.