table: A
-----------
value
1
2
3
sub-query: B
-----------
value
2
I need (A - B).
The below query works when B is not empty. Output = (1,3) as expected.
SELECT * FROM A
JOIN B
ON (A.value != B.value)
However, when the sub-query B is empty, the JOIN does an intersection of A with an empty B, and the output is an empty result-set.
And if I use LEFT JOIN, it does not subtract the row containing value 2 from table A.
Is it possible to write a single query for (A - B), irrespective of whether B is empty or not.
SELECT A.*
FROM A
LEFT JOIN B
ON A.value = B.value
WHERE b.value IS NULL
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments