Re: AAARRRGGG! QUERY HELP!!!!
Posted in 1996
Topics: General Discussion
Blair Maddock wrote:
>
> I have two tables that I need to compare. Table A and Table B.
>
> Two columns in A and two columns in B share similar values. I want to
> extract all A entries where the A columns
> are not in the B table colums.
> e.g. Table A has a record with 1,3 (columnc,columnd) in the two columns.
> Table B has 1,2 and 1,4 but no 1,3 as values from those two columns. I
> tried the following:
>
> select A.columnc,Acolumnd
> where A.columnc Not In
> (select B.columnc from B)
> and
> A.columnd Not In
> (select B.columnd from B)>
> and It didn't work
>
> Help
Try both of these. Depending on table sizes, one may be much faster...
SELECT A.columnc, A.columnd FROM A
WHERE NOT EXISTS (SELECT * FROM B
WHERE A.columnc = B.columnc AND a.columnd = B.columnd);
or (Even though this is 2 stataments, it can be faster)
SELECT A.columnc, A.columnd, B.columnc AS XXX
FROM A, OUTER B
WHERE A.columnc = B.columnc AND A.columnd = B.columnd
INTO TEMP YYY;
SELECT * FROM YYY
WHERE XXX IS NULL;