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?
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)
The fastest is the Left Join
SELECT * FROM A LEFT JOIN B ON A.X = B.X WHERE B.X IS NULL
use it :
select * from a where x not in (select x from b)