Let's say I have two identical tables, A and B, with the row "x".
I want to select all elements in A, where the value of x in A is not in any value of x of B.
How do I do that?
You could also do something like this:
SELECT * FROM TableA
LEFT JOIN TableB on TableA.X = TableB.X
WHERE TableB.X IS NULL
(For the very straightforward example in your question, a NOT EXISTS
/ NOT IN
approach is probably preferable, but is your real query is more complex, this is an option you might want to consider; if, for instace, you want som information from TableB where there is a match, but also want to know where there isn't one)
I'm having some trouble to understand what you need.
Anyway try this:
SELECT * FROM tableA
WHERE x not IN (SELECT x FROM tableB)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With