select from multi tables
| From: | Griffiths, Daniel | Date: | Mon, 03 Feb 2003 12:54:20 +0000 |
| Subject: | select from multi tables | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-25364@lists.php.net to get a copy of this message | ||
Hi All,
I have a situation where I need to get data from more than one table, but where the fields in the
table are identical, the two tables are holding data for different years. The queries I would like
to execute would be something along the lines of this: -
SELECT SUM(T1.F1) AS C1, SUM(T2.F1) AS C2 FROM T1, T2
Which I would like to give the total of T1.F1 in C1 and the total of T2.F1 in C2.
What I get however is the sum of T1.F1 * sum of T2.F1 in both result fields and the number of
records found as being the sum of the number of records in T1 * those in T2.
What I would like to do eventually with this is get the sum of F1 from any number of tables each
representing a year as I don't want to lump all my data into one big table that will get out of
hand.
Can anyone tell me the right way to go about this?
Cheers
Dan