>text TO query TEXTMERGE noshow > >SELECT distinct(data.acc_code) as acc_code ,max(data.acc_name) as acc_name, >sum(data.qty)as qty, >sum(data.cr_amount)as c_ramount >from ( > >SELECT acc_code ,acc_name, qty, cr_amount > from crsalp where substring(acc_code,1,2)='32' and type='P' > >union all > >SELECT acc_code ,acc_name, qty, cr_amount > from cashsalp where substring(acc_code,1,2)='31' and type='P' >) as data >group by >data.acc_code > >ENDTEXT >Try
text TO query TEXTMERGE noshow SELECT acc_code, acc_name, sum(data.qty) as qty, sum(data.cr_amount) as cr_amount from ( SELECT acc_code ,acc_name, qty, cr_amount from crsalp where acc_code like '32%' and type='P' union all SELECT acc_code ,acc_name, qty, cr_amount from cashsalp where acc_code like '31%' and type='P' ) as data group by acc_code, acc_name ENDTEXTDo you have multiple rows with the same code in your tables? From the first table you're taking accounts starting from 32 and from the second starting with 31. Also, I assumed that each acc_code has unique name.