Here I have 2 tables 1st table consist of 10 rows of acnumber column and 10 rows of opening_balance column. 2nd table consists of 3 of those acnumber in a column having made transaction several times mentioned in transaction_type column as 'Deposit' or 'Withdrawal' and transaction_amount column .
so I have to select all acnumber and their deposits made i.e opening balance+deposits.If no transaction available in table 2 then add opening balance and 0. I tried something like this
select a1.acnumber,a1.opening_balance+if (a1.acnumber not in (a2.acnumber),0,sum(a2.transaction_amount))
from account a1 left join trandetails a2
on a1.acnumber=a2.acnumber
where a2.transaction_type like'Deposit'
group by a2.acnumber;
But it returns only acnumber mentioned in both tables.Any suggestions???