Brug bare NOT IN
for at finde de poster, der ikke matcher new_table g
, og samles med posterne hentet af INNER JOIN
SELECT f.id_hist, f.producto, f.price
FROM TABLE(fnc_historical('JAP')) f
WHERE f.id_hist NOT IN
(SELECT DISTINCT f.id_hist
FROM TABLE(fnc_historical('JAP')) f
inner join new_table g on (f.id_new = g.id_hist)
)
UNION
SELECT f.id_hist, f.producto, g.new_price
FROM TABLE(fnc_historical('JAP')) f
inner join new_table g on (f.id_new = g.id_hist)