Does Snowflake CROSS JOIN support referencing other tables in join? This statement produces the error:
SQL compilation error: Invalid expression [T.ID1] in VALUES clause
WITH t AS
(
SELECT *
FROM (VALUES
(1, 2)
, (3, 4)
) x(id1, id2)
)
SELECT
t.*
, x.*
FROM t
CROSS JOIN (VALUES
(t.id1)
, (t.id2)
) x(id3)
This works as expected in MSSQL (using CROSS APPLY instead of CROSS JOIN).
However, hardcoding the values in the cross join works, but is not practical for my use case:
WITH t AS
(
SELECT *
FROM (VALUES
(1, 2)
, (3, 4)
) x(id1, id2)
)
SELECT
t.*
, x.*
FROM t
CROSS JOIN (VALUES
(1)
, (2)
, (3)
, (4)
) x(id3)
It produces the expected result:
ID1,ID2,ID3
1,2,1
3,4,1
1,2,2
3,4,2
1,2,3
3,4,3
1,2,4
3,4,4
Is there another way to produce the desired result in Snowflake?