In my Android app I have a database with two rows of interest.
table1 table2
|_id | name | |_id | table1_id |amount
I want to have a query that returns each row in table one augmented with the sum of the row amount for each row in table2 with a table1_id that corresponds to the _id in table 1. This is what I came up with so far:
SELECT table1._id, table1.name, SUM(amount)
FROM table1 LEFT OUTER JOIN table2
USING(table1._id,table2.table1._id) ;
This one returns a row with 0 in the SUM(amount) column, also when table 1 is completely empty ( result |-|-|0| ). I would like the result to be completely empty when table1
is empty. When there are no correspondences for a particular row in table1
I would like them to just be augmented with 0.
Any thoughts on improving the query?
Aucun commentaire:
Enregistrer un commentaire