c# - left join mysql database -


i have 3 tables( products,bill_details , bills) , want retrieve quantity of each product in bill_details table, below query give me products in bill_details table "just", , if bill_details empty, nothing retrieved !

enter image description here

and 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    (((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 on b.bill_id = a.bill_id)  left join bills aaa on bbb.bill_id = aaa.bill_id    a.cus_sup=1 , aaa.cus_sup=0 , a.archived=0 , aaa.archived=0  group p.prod_id,p.prod_name,p.prod_cost,p.prod_expdate, p.prod_bonusinfo,p.prod_note order p.prod_name asc; 

your where clause checking against tables left joined. doing that, removing rows unmatched in left joins. not want.

instead, want move conditions in join clauses themselves, this:

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    (((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 on b.bill_id = a.bill_id , a.cus_sup=1 , a.archived=0)  left join bills aaa on bbb.bill_id = aaa.bill_id , aaa.cus_sup=0 , aaa.archived=0  group p.prod_id,p.prod_name,p.prod_cost,p.prod_expdate, p.prod_bonusinfo,p.prod_note order p.prod_name asc; 

Comments

Popular posts from this blog

Android : Making Listview full screen -

javascript - Parse JSON from the body of the POST -

Revit Family Rename in a project -