I have 3 tables( products,bill_Details and bills) , i want to retrieve quantity of each product in bill_details table, the below query just give me the products which are in bill_details table "just", and if bill_details empty, nothing retrieved !
and this is my query:
select p.prod_Id,p.prod_Name,
sum(b.de_Quantity+b.de_Bonus) - sum(bbb.de_Quantity+bbb.de_Bonus),
p.prod_Cost,p.prod_ExpDate,p.prod_BonusInfo,p.prod_Note
from
(((products p left JOIN bill_Details b on p.prod_Id=b.prod_Id)
left JOIN bill_Details bbb on p.prod_Id=bbb.prod_Id )
left JOIN bills a on b.bill_Id = a.bill_Id)
left JOIN bills aaa on bbb.bill_Id = aaa.bill_Id
where
a.cus_Sup=1 and aaa.cus_Sup=0 and a.archived=0 and aaa.archived=0
group by p.prod_Id,p.prod_Name,p.prod_Cost,p.prod_ExpDate,
p.prod_BonusInfo,p.prod_Note order by p.prod_Name asc;