Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.