Can following Query be optimised for Teradata?
We need all records from small table A, plus all corresponding records from large table B, that match on a nonunique key
Or, in other words: everything except all from B that has no match in A.
Maybe something with a JOIN? Or a Subselect that is a non-correlated Query, does that also apply to Teradata?
SELECT a.nonunique
, a.colX
FROM small_tab a
UNION ALL
SELECT b.nonunique
, b.colY
FROM large_tab b
WHERE EXISTS (
SELECT 1
FROM small_tab a
WHERE a.nonuniqe = b.nonunique
);
Thanks for the help!
=========UPDATE====
based on quanos answer in this MySQL question, would following statement with a noncorrelated subquery be faster also in Teradata?
SELECT a.nonunique
, a.colX
FROM small_tab a
UNION ALL
SELECT b.nonunique
, b.colY
FROM large_tab b
WHERE b.nonunique IN
(
SELECT DISTINCT nonunique
FROM small_tab
GROUP BY nonunique
)
I cannot test in Teradata currently, only have an Oracle instance at home..