hi to all

Ihave a main table with unique "id" with relation in table1 and table2 "main_id". I want to query and ouput the information from main table including the total of debitval from table1 and creditval from table2. Any help would greatly appreciated.

Thanks in advance.

maintable

id payee description reference_no
1 john advance 1
2 dave request 2

table1

id main_id debitval
1 1 5.00
2 1 10.00
3 2 6.00
4 2 7.00

table2

id main_id creditval
1 1 5.00
2 1 10.00
3 1 15.00
4 2 4.00

output table should be like this

id payee description reference_no debitval creditval
1 john advance 1 15.00 30.00
2 dave request 2 13.00 4.00