I have these two tables (Article and 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 to get the sales for 2011/01/01: article and count
2011-01-01 Milk 0
2011-01-01 Apple 2
2011-01-01 Bread 1
...
But I don't know how to show "Milk: 0" because it didn't sell milk that day.
This query doesn't work:
SELECT s.date, a.name, COUNT(*)
FROM article a
LEFT JOIN sale s ON a.id = s.idArticle
WHERE s.date = "2011-01-01"
GROUP BY s.date, a.name
But I don't know how to show "Milk: 0" because it didn't sell milk that day.Have you realy read this question?