I have two tables. Transaction(ID, TERMINALID) and Terminal(ID, TERMINALID, EXPORT_DATE). The goal is to obtain for each row from Transaction table newest recored from Terminal table. Snowflake is used as a backend.
I have this SQL query:
SELECT tr.ID,
(SELECT te.ID
FROM "Terminal" te
WHERE te.TERMINALID = tr.TERMINALID
ORDER BY te.EXPORT_DATE DESC
LIMIT 1)
FROM "Transaction" tr;
But I get this error:
SQL compilation error: Unsupported subquery type cannot be evaluated
Error disappears if I replace tr.TERMINALID with a specific value. So I can't reference parent table from nested SELECT. Why this is not possible? Query works in MySQL.
I'm afraid Snowflake doesn't support correlated subqueries of this kind.
You can achieve what you want by using
FIRST_VALUE
to compute best per-terminalid id :You can run subqueries first to see what they do.
We're working on making our support for subqueries better, and possibly there's a simpler rewrite, but I hope it helps.