Re: SQL from 2 tables

From: Lee Miller <lpm_at_newsguy.com>
Date: Tue, 22 May 2001 15:02:15 -0400
Message-ID: <9eed1f01ebo_at_enews3.newsguy.com>


Point of clarification. Do you want to find any number that is >1 in either table or do you want to find any number that occurs more than once in either table? If it is the former you could just union all two selects with the appropriate criteria perhaps something like.

(
select

    'table1' as tablename,
    numeric1,
    numeric2,
    numeric3
from

    table1
where

    numeric1 > 1 or
    numeric2 > 2 or
    numeric3 > 1

)
union all
(
select

    'table2' as tablename,
    numeric1,
    numeric2,
    numeric3
from

    table2
where

    numeric1 > 1 or
    numeric2 > 2 or
    numeric3 > 1

)

of course the tablename is optional if you don't care about which table the data came from. if what you are looking for it the later case that's fairly easy also. Post if that's the case and I'm sure I (or someone else) can throw something together.

"Robin Boscia" <rboscia_at_att.com> wrote in message news:9ee6qd$d8i6_at_kcweb01.netnews.att.com...
> I am a newbie with a slight problem
>
>
> I have 2 tables that have the same columns with the same datatypes in them
> (mostly all numbers)
>
> I want to query both tables to find any number that is > 1 in either of
 the
> tables in any of the columns, rows. I don't want just a count of how
 many,
> I want to see the actual data.
>
> This seems real simple, but for some reason, I can't get it to give me the
> data I want.
>
> Thanks
> Robin
>
>
>
> Example:
>
>
> Table A Table B
>
> col1 1 col1 2
> col2 0 col2 3
> col3 25 col3 0
>
>
>
Received on Tue May 22 2001 - 21:02:15 CEST

Original text of this message