Link to home
Start Free TrialLog in
Avatar of jmvega00
jmvega00

asked on

How To select all values not included in a join

I would like to know how to select all values not included in a join:

Example:

select tbl1.value from tbl1 join tbl2
on tbl1.value = tbl2.value
results:
2, 4, 6, 8

Now how can i select all the values that are NOT in that join...
Avatar of udaya kumar laligondla
udaya kumar laligondla
Flag of India image

use select tbl1.value from tbl1 join tbl2
on not (tbl1.value = tbl2.value)
Avatar of Guy Hengel [angelIII / a3]
this will do:_
select tbl1.value 
from tbl1 left join tbl2
  on tbl1.value = tbl2.value
where tbl2.value is null

Open in new window

Avatar of jmvega00
jmvega00

ASKER

udaya:
for some reason ur code isn't working. It is doing the same as if I had done:
select tbl1.value from tbl1 join tbl2
on (tbl1.value != tbl2.value)

lets say tbl1 has: 1, 2, 3, 4, 5, 6, 7, 8
lets say tbl2 has 2, 4, 6
so the join returns 2, 4, 6
I want it to return 1, 3, 5, 7, 8

for some reason the code i'm using is returning the stuff not in the union as well as the values in the union...
ASKER CERTIFIED SOLUTION
Avatar of Guy Hengel [angelIII / a3]
Guy Hengel [angelIII / a3]
Flag of Luxembourg image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
thank you angel, your code did the trick.