sorry, dan, your query produces these results:
Code:
id debitval creditval
1 45.0 60.0
2 13.0 8.0
your results are inflated because of cross join effects
this query --
Code:
SELECT maintable.id
, maintable.payee
, maintable.description
, maintable.reference_no
, d.total_debit
, c.total_credit
FROM maintable
LEFT OUTER
JOIN ( SELECT main_id
, SUM(debitval) AS total_debit
FROM table1
GROUP
BY main_id ) AS d
ON d.main_id = maintable.id
LEFT OUTER
JOIN ( SELECT main_id
, SUM(creditval) AS total_credit
FROM table2
GROUP
BY main_id ) AS c
ON c.main_id = maintable.id
produces the correct results --
Code:
id payee description reference_no total_debit total_credit
1 john advance 1 15.0 30.0
2 dave request 2 13.0 4.0
Bookmarks