Go Back   Rhinocerus > Newsgroup > Newsgroup comp.databases.mysql

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 11-23-2009, 02:39 PM
rjre
Guest
 
Posts: n/a
Default Join

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
Reply With Quote
Alt Today
Advertising
 
and become member of Rhinocerus
Standard Sponsored Links

  #2 (permalink)  
Old 11-23-2009, 03:25 PM
Lennart
Guest
 
Posts: n/a
Default Re: Join

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
Reply With Quote
  #3 (permalink)  
Old 11-23-2009, 03:29 PM
Jerry Stuckle
Guest
 
Posts: n/a
Default Re: Join

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
==================
Reply With Quote
  #4 (permalink)  
Old 11-23-2009, 04:10 PM
toby
Guest
 
Posts: n/a
Default Re: Join

On Nov 23, 10:39*am, 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


Reply With Quote
  #5 (permalink)  
Old 11-23-2009, 04:12 PM
rjre
Guest
 
Posts: n/a
Default Re: Join

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 (
> * * 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- Hide quoted text -
>
> - Show quoted text -


perfect! - thx vm
Reply With Quote
 
Reply

Popular Tags in the Forum
join

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
performance issue after upgrade to oracle 11.2.0.1 linux 32 bit. lsllcm Newsgroup comp.databases.oracle.server 31 11-20-2009 01:24 PM
Re: performance issue after upgrade to oracle 11.2.0.1 linux 32 bit. lsllcm Newsgroup comp.databases.oracle.server 0 11-04-2009 11:03 AM
Re: SQL Left Join Warning - Join 3 tables Sigurd Hermansen Newsgroup comp.soft-sys.sas 0 11-05-2008 07:17 PM
Re: A better JOIN method Sigurd Hermansen Newsgroup comp.soft-sys.sas 0 08-14-2007 09:10 PM
Re: SQL - why is Left Join 2x less efficient than Inner Join? Sigurd Hermansen Newsgroup comp.soft-sys.sas 0 07-19-2005 08:16 PM



All times are GMT. The time now is 06:49 PM.


Copyright ©2009

LinkBacks Enabled by vBSEO 3.3.0 RC2 © 2009, Crawlability, Inc.