MYSQL SELECT SUM() BY DATE IF NO MATCH RETURN 0 <p>I have connected three tables to each other. I'm querying keywords + statistics.</p> <p>I need to get data out by date range, and if there is no data for that specific date range i would like it to return 0 statistics</p> <p>Lets say my query is:<BR/> SELECT keyword,SUM(stat) FROM keywords WHERE date >='2012-07-10' GROUP BY keyword;<BR/><BR/> It would return<br/> |my keyword 1|3|<br/> |my keyword 2|6|<br/> <br/>Example table content:<br/> | id | keyword | stat | date | keywordGroup |<br/> | 1 | my keyword 1 | 2 | 2012-07-11 | 1 |<br/> | 2 | my keyword 1 | 1 | 2012-07-12 | 1 |<br/> | 3 | my keyword 2 | 6 | 2012-07-11 | 1 |<br/> | 4 | my keyword 3 | 10 | 2012-07-09 | 1 |<br/> <br/>But there are some keywords which have no stats for that date range<br/> but I would still like to get those keywords showing 0 as stats. <br/><br/>Like this:</p> <p>|my keyword 1|3|<br/> |my keyword 2|6|<br/> |my keyword 3|0|<br/><br/> The problem is that the where clause blocks values that are not found, is there a workaround.<br/>As I said I have three tables with relations, I use LEFT JOIN to query data, for simplification I left that part out of my example query.</p> <p>Table: Campaigns<br/> id<br/> name<br/></p> <p>Table: KeywordGroup<br/> id<br/> name<br/> campaign<br/></p> <p>Table: KeywordData<br/> id<br/> keyword<br/> stat<br/> date<br/> keywordGroup<br/></p>