I have a table "tbA" where the primary column "a1" needs to be referenced by the "tbB" table by the "fk_a1" column
tbA
id | nome |
---+------+--
1, 'aaaa'
2, 'bbbbb'
3, 'cccc'
4, 'ddddd'
tbB
id | fk_a1 | valor_1 | valor_2 |
---+-------+----------+----------
1, 2, 500.00, 100.00
2, 1, 150.00, 200.00
3, 1, 100.00, 50.00
4, 3, 10.00, 0.00
5, 3, 100.00, 20.00
Considering that the relationship between the two tables is something like
SELECT * FROM tbA a LEFT JOIN tbB b ON b.fk_a1 = a.id
Once this relationship is complete, list the records, assuming the main table is tbA and the tbB summed values will come in the list as
id | nome | soma_1 | soma_2 |
---+------+---------+---------
1, 'aaaa', 250.00, 50.00
2, 'bbbbb', 500.00, 100.00
3, 'cccc', 110.00, 20.00
4, 'ddddd', 0.00, 0.00
I do not know exactly how to do this, thank you.