Jump to content

SUM() Help


n3mesis125

Recommended Posts

Hey FOlks,

 

How can I fix an error so that if I'm using SUM() with two tables and lets say Table B doesn't return any values for the WHERE clause?

 

IE:

 

SELECT SUM(t1.salary) as t1total, SUM(t2.salary) as t2total
FROM table1 as t1
LEFT JOIN table2 as t2 ON (t2.id = t1.id)
WHERE t1.date BETWEEN '2008-10-01' AND '2008-10-20'
AND t1.username = 'test.account'
GROUP BY t1.date

 

Table 2 may not return any data if the user we are looking for hasn't submitted anything. For some reason mysql doesn't return any data at all when it can't SUM() an empty resultset?

 

Hope this makes sense, I tried using IFNULL(t2.salary,0) but it doesn't seem to work.

 

 

Thanks,

n3m.

Link to comment
https://forums.phpfreaks.com/topic/132611-sum-help/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.