I have database value, for example
table name: a_table
===================================
| userId | userName |
===================================
===================================
| abc | Alice |
| bcd | Rachel |
| efg | Raymond |
===================================
table name: b_transaction
=============================================
| transCode | userId | value |
=============================================
=============================================
| 1 | abc | 100 |
| 2 | abc | -200 |
| 3 | abc | 300 |
=============================================
My goal is, get sum of all data, if user dont have row in table transaction, they must be 0. But when I try this query
SELECT a.userId, a.userName, SUM(b.value)
FROM a_table a
LEFT JOIN b_transaction b ON a.userId = b.userId
The result just return 1 row
================================================
| userId | userName | value |
================================================
================================================
| abc | Alice | 200 |
================================================
How to achieve that? Thaanks~