Re: SQL from 2 tables

From: Randall Roberts <randall_at_filer.org.nospam>
Date: Fri, 25 May 2001 07:33:07 -0700
Message-ID: <3b0e6d44$1_2_at_news.pcmagic.net>


Robin Boscia <rboscia_at_att.com> wrote in message news:9eerga$d8i9_at_kcweb01.netnews.att.com...
> > "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
> > >

Robin;

I really can't think of a way to do this in SQL; PL/SQL yes, but not SQL. However, when I see a statistical problem like this it reminds me of an application I once built that I wish I had built differently. I had a table laid out like so:

Date Facility Statistic1 Statistic2 Statistic3.... Statistic120 (PK = Date, Facility)

I looked at my options and decided to build it like that because I thought making the table like this would be too difficult:

Date Facility Stat_Name Stat_Value (PK = Date, Facility, Stat_Name)

In the long run it was far more work using the wide horizontal table layout. Now, every time I see colum names (rather than values) in rows, I think of that application. Your application compounds the problem by comparing columns in two tables.

Best!

Randall Received on Fri May 25 2001 - 16:33:07 CEST

Original text of this message