mysql - Selecting all rows from one table where condition in joined table -
i have products table , productionreport table in database.
the productionreport table captures weekly production information each product. app report on information.
table structures
productionreport
productionreportid, productid, date, qty
1, 1, 2013-04-08, 50
2, 2, 2013-04-08, 12
products
productid, productname
1, skin cream
2, peanut oil
3, bath salts
4, shampoo
my page uses gridview list products (select productid, productname products
) , join in productionreport table display list of products , production values week user can update.
my problem sql query populate gridview. gets rows there joined value in both tables:
select pro.productname, pr.productionreportid, ifnull(pr.qty, 0) qty products pro left join productionreport pr on pro.productid = pr.productid date(pr.date) = '2013-04-08'
so, given above described data, i'm expecting following resultset
skin cream, 1, 50
peanut oil, 2, 12
bath salts, 0, 0
shampoo, 0, 0
unfortunately, i'm getting first 2 rows. believe that's because of clause targeting column in joined table. if that's case, it's serious flaw in logic, don't know it.
any suggestions?
try this
select pro.productname, pr.productionreportid, ifnull(pr.qty, 0) qty products pro left join productionreport pr on pro.productid = pr.productid , date(pr.date) = '2013-04-08'
basically move date condition clause join clause
Comments
Post a Comment