MySQL where condition but not limited by it
Posted
by Manny Calavera
on Stack Overflow
See other posts from Stack Overflow
or by Manny Calavera
Published on 2010-05-04T22:53:15Z
Indexed on
2010/05/04
22:58 UTC
Read the original article
Hit count: 322
Hello. I would like to run a query on my database like this:
SELECT SUM( t1.value ) AS total1, SUM( t2.value ) AS total2, SUM( t3.value ) AS total3, SUM( t4.value ) AS total4
FROM pay1 t1, pay2 t2, pay3 t3, pay4 t4
WHERE t1.date = '2010-04-29'
AND t2.date = '2010-04-29'
AND t3.date = '2010-04-29'
AND t4.date = '2010-04-29'
I am generating a report on payments and I would like to see a total of payments from each table based on the matching date. The problem is that some of the tables would not meet the condition of date and I want them to show up with 0 value if not. Currently, if any of the tables does not match the date, I get 0 results. I want to display value of 0 anywhere the date is not met and other fields should appear with the found values.
The perfect operand for me would be "ANDOR" so that it won't be limited by any date that doesn't math in any table. Unfortunately, ANDOR does not exist as I am aware of so what should I do ?
Can anyone help ? Thanks.
© Stack Overflow or respective owner