SELECT * FROM (SELECT tbl_item.name,tbl_item.brid,tbl_brand.name AS brand,tbl_item.catid,tbl_category.name AS category,tbl_item.scatid,tbl_stock.code,tbl_stock.cost,tbl_stock.price,(SELECT COALESCE ((SELECT SUM(avqty) FROM tbl_brstock WHERE unqid=tbl_stock.unqid GROUP BY unqid),0))+(SELECT COALESCE ((SELECT SUM(avqty) FROM tbl_brstock WHERE unqid=tbl_stock.unqid GROUP BY unqid),0)) AS avqty FROM tbl_stock LEFT JOIN tbl_item ON tbl_item.id=tbl_stock.pid LEFT JOIN tbl_brand ON tbl_brand.id=tbl_item.brid LEFT JOIN tbl_category ON tbl_category.id=tbl_item.catid) ofitm WHERE avqty>0