> Hello,
>
 > I don't understand the following, who can help?
>
 > I have got two queries:
> SELECT SUM(fielda) FROM table1
> and
> SELECT SUM(fieldb) FROM table2
>
> I thought this would be the same as:
> SELECT SUM(fielda.table1),SUM(fieldb.table2)   FROM table1, table2.
> But, itn't, why?
>
>
> Tnx,
>
> Bas Jobsen

You have to remember the table1,table2 is the same as table1 JOIN table2.
What does this mean?
Try this code and I think you will get a better idea of what is happening

Select table1.fielda,table2.fieldb from table1,table2;

Say table1.fielda is an int with values 1-5 and table2.fieldb is an int with
values 1-7.

The above Select would return 35 rows, because the join (,) tells it to
return a set with every combination
of fielda and fieldb (1,1 2,1 3,1 4,1 5,1 1,2 etc)  So

SELECT SUM(fielda.table1),SUM(fieldb.table2)   FROM table1, table2.

Will calculate every possible combination of fielda and fieldb and then give
you the sums of each column in that set
(105 and 140 in my example).  Does that make sense?

To do what I think you are trying to do you would use something like:
Select sum(table1.fielda),sum(table2.fieldb) from table1 LEFT JOIN table2 ON
table1.id=table2.id;

if table1.fielda has more rows.
If table2.fieldb has more rows use:

Select sum(table1.fielda),sum(table2.fieldb) from table2 LEFT JOIN table1 ON
table1.id=table2.id;

Hope that helps

Sheridan Saint-Michel
Website Administrator
FoxJet, an ITW Company
www.foxjet.com


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to