count - MySQL query with zero values -


i have these 2 tables (article , sale):

id  |  name     | ====+============ 1   |   milk    | 2   |   apple   | 3   |   bread   | ... |    ...    |   id  |   idarticle  |   date     | ====+==============+============= 1   |       2      | 2011-01-01 | 2   |       2      | 2011-01-01 | 3   |       3      | 2011-01-01 | 4   |       1      | 2011-01-02 | ... |      ...     |    ...     | 

i need sales 2011/01/01: article , count

2011-01-01 milk 0 2011-01-01 apple 2 2011-01-01 bread 1 ... 

but don't know how show "milk: 0" because didn't sell milk day.

this query doesn't work:

select s.date, a.name, count(*) article left join sale s on a.id = s.idarticle s.date = "2011-01-01" group s.date, a.name 

select "2011-01-01" date, a.name, ifnull(s.total, 0) article left join (     select idarticle, count(*) total     sale     date = "2011-01-01"     group idarticle ) s on a.id = s.idarticle 

Comments

Popular posts from this blog

java - Play! framework 2.0: How to display multiple image? -

gmail - Is there any documentation for read-only access to the Google Contacts API? -

php - Controller/JToolBar not working in Joomla 2.5 -