To give a simple example, let's say I have two tables
T1 T2
======= =======
Val Val
======= =======
1 1
2 3
4 4
5 5
6
The result set I want is
2
3
6
because those are the numbers contained in one but not the other. I know it can be done with something like
WITH cte1 (Val) AS (
SELECT Val
FROM T1
LEFT JOIN T2
ON T1.Val = T2.Val
WHERE Val IS NOT NULL
),
cte2 (Val) AS (
SELECT Val
FROM T2
LEFT JOIN T1
ON T1.Val = T2.Val
WHERE Val IS NOT NULL
)
SELECT *
FROM cte1
UNION WITH cte2
but is there a more compact and/or efficient way to do this?