SELECT 'I' as Ind, INV.Item_ID as ID, INV.Item_Name as ITEM, SALES.Quantity,  SALES.Subtotal from Sales_Inventory_Items as INV LEFT outer JOIN  (SELECT Inventory_Item_ID,SUM(SALES.Quantity ) as Quantity,  SUM(SALES.Subtotal )  as SubTotal  from Sales_Invoice_Details as SALES  JOIN Sales_Invoice_Main main  ON SALES.Voucher_No = main.Voucher_No WHERE str_to_Date(concat(main.Voucher_Date, substr(`TimeStamp`, 11,19)) ,'%Y-%m-%d %H:%i:%s') >=str_to_Date('$fromDateTime','%Y-%m-%d %H:%i:%s') AND str_to_Date(concat(main.Voucher_Date, substr(`TimeStamp`, 11,19)) ,'%Y-%m-%d %H:%i:%s') <=str_to_Date('$toDateTime','%Y-%m-%d %H:%i:%s') AND main.POC_Phone like '$f1' group by SALES.Inventory_Item_ID ) as SALES on  INV.Item_Id=SALES.Inventory_Item_ID where COALESCE(SALES.Quantity,0)>0