understanding NOT IN / IN

From: ciapecki <ciapecki_at_gmail.com>
Date: Tue, 17 Feb 2009 10:41:23 -0800 (PST)
Message-ID: <64ababe7-e9c2-41dd-a91f-d0cd2f53408f_at_v38g2000yqb.googlegroups.com>



Following situation:

create table a (org_id number, org_name varchar2(1));

insert into a values(1,'a');
insert into a values(2,'b');
insert into a values(3,'c');

create table b (name varchar2(1));
insert into b values('a');
insert into b values('b');

create table c (org_id number, org_name varchar2(1)); insert into c values(2,'b');
commit;

select * from a
where a.org_id not in (select org_id from b);
-- returns 0 rows

select * from a
where a.org_id in (select org_id from b);
-- returns all 3 rows from a

Why does it actually work?

there is no org_id in table b.
when you run
select org_id from b

        *
ORA-00904: "ORG_ID": invalid identifier

thanks,
chris Received on Tue Feb 17 2009 - 12:41:23 CST

Original text of this message