linking two selects
am 10.11.2007 15:08:35 von mantrid
I have two select statements below, that I wish to combine into one
SELECT cgttransactions.linkid, cgttransactions.userid,
cgttransactions.myvarid, cgttransactions.companyid,
Sum(cgttransactions.amount) AS SumOfamount, Avg(cgttransactions.price) AS
AvgOfprice, Sum(cgttransactions.stamp) AS SumOfstamp,
Sum(cgttransactions.comm) AS SumOfcomm, cgttransactions.datetime,
cgttransactions.aimlisted
FROM cgttransactions
GROUP BY cgttransactions.linkid, cgttransactions.userid,
cgttransactions.myvarid, cgttransactions.companyid,
cgttransactions.datetime, cgttransactions.aimlisted
HAVING (((cgttransactions.userid)="1") AND ((cgttransactions.myvarid)=1) AND
((cgttransactions.companyid)="1"));
SELECT cgttransactions.linkid, cgttransactions.sellprice,
cgttransactions.sellcomm, cgttransactions.selldatetime
FROM cgttransactions;
the common field is linkid
How do I do this?
Thanks
Re: linking two selects
am 12.11.2007 21:13:41 von Michael Austin
mantrid wrote:
> I have two select statements below, that I wish to combine into one
>
> SELECT cgttransactions.linkid, cgttransactions.userid,
> cgttransactions.myvarid, cgttransactions.companyid,
> Sum(cgttransactions.amount) AS SumOfamount, Avg(cgttransactions.price) AS
> AvgOfprice, Sum(cgttransactions.stamp) AS SumOfstamp,
> Sum(cgttransactions.comm) AS SumOfcomm, cgttransactions.datetime,
> cgttransactions.aimlisted
> FROM cgttransactions
> GROUP BY cgttransactions.linkid, cgttransactions.userid,
> cgttransactions.myvarid, cgttransactions.companyid,
> cgttransactions.datetime, cgttransactions.aimlisted
> HAVING (((cgttransactions.userid)="1") AND ((cgttransactions.myvarid)=1) AND
> ((cgttransactions.companyid)="1"));
>
>
>
> SELECT cgttransactions.linkid, cgttransactions.sellprice,
> cgttransactions.sellcomm, cgttransactions.selldatetime
> FROM cgttransactions;
>
> the common field is linkid
> How do I do this?
> Thanks
>
>
a google search for mysql and join should provide you with some
interesting links on how and what "joins" are.
This is an example (I in no way am related to this link - it was one of
search result links) :
http://www.codinghorror.com/blog/archives/000976.html