select sod.*, sod.quantity - ifnull(sum(gind.gin_quantity),0) as out_qty  from 0p4_sale_order_detail sod
left join 0p4_good_issue_note_item_detail gind on gind.sale_order_detail_id=sod.sale_order_detail_id
where sod.sale_order_id=6
group by sod.sale_order_id
having ifnull(out_qty,0) > 0
