** Put all non agregated fields in GROUP BY to not have problems with SET ENGINEBEHAVIOUR ** Don't use ALLTRIM() SELECT products.prodid,; product.name,; product_price,; SUM(NVL(bill_items.qty,0)) AS OQty,; SUM(NVL(input_items.qty,0) AS IQty; FROM products; LEFT JOIN bill_items ON product.prodid == bill_items.prodid; LEFT JOIN input_items ON product.prodid == input_items.prodid; GROUP BY products.prodid,product.name, product_price; ORDER BY products.prodid ; INTO CURSOR output1