Hi,
I’m trying to get the sum of 2 fields from different tables. Only the below code show correct results:
$query = mysql_query("
SELECT (SELECT SUM(var) FROM t1 WHERE t1.name = t2.name + (SELECT SUM(var) FROM t2 WHERE t1.name = t2.name) AS cvar, t1.name AS name
FROM t1, t2
WHERE t1.name = t2.name
GROUP BY t1.name
ORDER BY SUM(t1.var) + SUM(t2.var) DESC");
while ($career = mysql_fetch_array($query))
{
echo $career['name'] . ' - ' .$career['cvar'] . '<br />';
}
It works but it’s not sorted out correctly. Also, I would have wanted to show the results even if t1.name is not present in t2 and vice versa, but if I remove the WHERE clause after the SUM functions, it throws up an error, same when I change the ORDER BY clause to anything.
Help with be really, and I mean REALLY appreciated.
Thanks in advance,
darkwind777