I have a query that takes data from 2 tables. It works, but the two SUMs return NULL if there are no values. How can I get zero instead?
SELECT SUM(g.field1),
SUM(g.field2),
c._id,
c.field_1,
c.field_3
FROM Table1 g
JOIN Tabel2 c
WHERE ( c.field_1 = g.field5 )
The SUM functions returns NULL if there are no non-NULL values.
To get a return value of 0 even if there are no input values, just replace SUM with the TOTAL function:
SELECT TOTAL(g.field1),
TOTAL(g.field2),
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With