trouble with exclusionary SQL query
Posted in 1998
Hi, Everyone!
I'm trying to formulate a query to select values from a column in one table
where the values do not appear in a column in a second table. I've tried
several different ways of querying and I either get all the rows from the
first table (even if they are in the second table) or no rows at all.
TAB1.A is char(20) and TAB2.B is varchar(20). We're using ODS 7.23 on
HP-UX.
I've tried the following:
This got me everything in TAB1, even if it was in TAB2:
select distinct T1.A
from TAB1 as T1, TAB2 as T2
where T1.A != T2.B
This also got me everything in TAB1, even if it was in TAB2:
select distinct T1.A
from TAB1 as T1, outer TAB2 as T2
where T1.A != T2.B
This got me 0 rows:
select A from TAB1
where A not in( select B from TAB2 )I'd really appreciate your help in this because I'm stuck. Thanks!
--
Wanda