Join

  • Follow


Afternoon all...

Can someone help me with a join...as I now have no hair and am having
trouble typing because of all the caffine...

I have three tables: TABLE1, TABLE2 and TABLE3.

All tables have the IDENTIFIER, QUANTITY and DATE.

What I would like is to be able to produce a query that gives a list
(for CURDATE()) a list of identifiers and quantities where each
identifier is shown once but if they appear in multiple tables to sum
the resulting quantities together...

thank you very much

richard
0
Reply rjredwards (9) 11/23/2009 3:39:43 PM

On 23 Nov, 16:39, rjre <rjredwa...@googlemail.com> wrote:
> Afternoon all...
>
> Can someone help me with a join...as I now have no hair and am having
> trouble typing because of all the caffine...
>
> I have three tables: TABLE1, TABLE2 and TABLE3.
>
> All tables have the IDENTIFIER, QUANTITY and DATE.
>
> What I would like is to be able to produce a query that gives a list
> (for CURDATE()) a list of identifiers and quantities where each
> identifier is shown once but if they appear in multiple tables to sum
> the resulting quantities together...
>
> thank you very much
>
> richard

I'm not sure I understand your question, but it sounds like what you
need is a union, not a join (even though it might be possible to
express the same thing via joins, it is not very intuitive). Is this
what you mean?

select identifier, some_date, sum(quantity) from (
    select identifier, some_date, quantity from t1
    union all
    select identifier, some_date, quantity from t2
    union all
    select identifier, some_date, quantity from t3
) x group by identifier, some_date;


/Lennart
0
Reply Lennart 11/23/2009 4:25:23 PM


rjre wrote:
> Afternoon all...
> 
> Can someone help me with a join...as I now have no hair and am having
> trouble typing because of all the caffine...
> 
> I have three tables: TABLE1, TABLE2 and TABLE3.
> 
> All tables have the IDENTIFIER, QUANTITY and DATE.
> 
> What I would like is to be able to produce a query that gives a list
> (for CURDATE()) a list of identifiers and quantities where each
> identifier is shown once but if they appear in multiple tables to sum
> the resulting quantities together...
> 
> thank you very much
> 
> richard

Richard,

Your question is confusing.  How about the layout of your tables, some 
sample data, and the results you hope to achieve?

-- 
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
0
Reply Jerry 11/23/2009 4:29:48 PM

On Nov 23, 10:39=A0am, rjre <rjredwa...@googlemail.com> wrote:
> Afternoon all...
>
> Can someone help me with a join...as I now have no hair and am having
> trouble typing because of all the caffine...
>
> I have three tables: TABLE1, TABLE2 and TABLE3.
>
> All tables have the IDENTIFIER, QUANTITY and DATE.

If these are the same entity why are they in 3 tables?

>
> What I would like is to be able to produce a query that gives a list
> (for CURDATE()) a list of identifiers and quantities where each
> identifier is shown once but if they appear in multiple tables to sum
> the resulting quantities together...
>
> thank you very much
>
> richard

0
Reply toby 11/23/2009 5:10:19 PM

On 23 Nov, 16:25, Lennart <erik.lennart.jons...@gmail.com> wrote:
> On 23 Nov, 16:39, rjre <rjredwa...@googlemail.com> wrote:
>
>
>
>
>
> > Afternoon all...
>
> > Can someone help me with a join...as I now have no hair and am having
> > trouble typing because of all the caffine...
>
> > I have three tables: TABLE1, TABLE2 and TABLE3.
>
> > All tables have the IDENTIFIER, QUANTITY and DATE.
>
> > What I would like is to be able to produce a query that gives a list
> > (for CURDATE()) a list of identifiers and quantities where each
> > identifier is shown once but if they appear in multiple tables to sum
> > the resulting quantities together...
>
> > thank you very much
>
> > richard
>
> I'm not sure I understand your question, but it sounds like what you
> need is a union, not a join (even though it might be possible to
> express the same thing via joins, it is not very intuitive). Is this
> what you mean?
>
> select identifier, some_date, sum(quantity) from (
> =A0 =A0 select identifier, some_date, quantity from t1
> =A0 =A0 union all
> =A0 =A0 select identifier, some_date, quantity from t2
> =A0 =A0 union all
> =A0 =A0 select identifier, some_date, quantity from t3
> ) x group by identifier, some_date;
>
> /Lennart- Hide quoted text -
>
> - Show quoted text -

perfect! - thx vm
0
Reply rjre 11/23/2009 5:12:46 PM

4 Replies
147 Views

(page loaded in 1.21 seconds)

5/18/2013 9:10:17 AM


Reply: