Icon View Thread

The following is the text of the current message along with any replies.
Messages 1 to 3 of 3 total
Thread Compare records in 2 tables
Fri, Nov 28 2008 4:31 AMPermanent Link

Pat
Hi all,

I have two v4 tables (one field in each). I want to find the records
that are in one table and not the other. Say

Table A:
Apple
Orange
Pear

Table B:
Apple
Banana
Pear
Grape

The required output would be
Orange
Banana
Grape

The long to do it would be to iterate through Table A and find which
record is not found in Table B, then do the same with Table B. Is
there something like a 2 line SQL that will do this?

Thanks.

Pat


Fri, Nov 28 2008 5:57 AMPermanent Link

"John Hay"
Pat

> I have two v4 tables (one field in each). I want to find the records
> that are in one table and not the other. Say
>
> Table A:
> Apple
> Orange
> Pear
>
> Table B:
> Apple
> Banana
> Pear
> Grape
>
> The required output would be
> Orange
> Banana
> Grape

How about

SELECT fieldname FROM TableA WHERE fieldname NOT IN (SELECT fieldname FROM
TableB)
UNION
SELECT fieldname FROM TableB WHERE fieldname NOT IN (SELECT fieldname FROM
TableA)

John

Fri, Nov 28 2008 6:48 PMPermanent Link

Pat
Hi John,

>> The long to do it would be to iterate through Table A and find which
>> record is not found in Table B, then do the same with Table B. Is
>> there something like a 2 line SQL that will do this?

>How about
>
>SELECT fieldname FROM TableA WHERE fieldname NOT IN (SELECT fieldname FROM
>TableB)
>UNION
>SELECT fieldname FROM TableB WHERE fieldname NOT IN (SELECT fieldname FROM
>TableA)

it works great   Smile

thanks very much

Pat
Image