MySQL SELECT with LEFT JOIN and GROUP problem
I have a main table <b>foo</b> with dates and values, and a table <b>bar</b> with exception dates and values. If the date exists in the <b>bar</b> table, that value applies, otherwise the default <b>foo</b> value. So, for example:

<pre>
<b>foo</b>
id  date        value
1   2009-11-19  25
2   2009-11-20  50

<b>bar</b>
id  date        value
1   2009-11-19  50
</pre>

To select the right values I use the following type of query:
<code><pre>
SELECT
  f.date,
  IF (f.date = b.date, b.value, f.value) AS value
FROM foo f
LEFT JOIN bar b
  ON b.date = f.date
</pre></code>

This works fine. The date "2009-11-19" exists in <b>bar</b>, so it selects the 50-value. But now I'd like to GROUP the results by MONTH, using this query:
<code><pre>
SELECT
  MONTH(f.date) AS month,
  IF (f.date = b.date, b.value, f.value) AS value
FROM foo f
LEFT JOIN bar b
  ON b.date = f.date
GROUP BY month
</pre></code>

It now returns the results by month, so the grouping works fine. However, it now ignores the <b>bar</b> values, and it seems it doesn't do any matching at all. The total for the month is 75 (25 from foo + 50 from foo) instead of 100 (50 from bar + 50 from foo).

Is there a way to make this work? So that it selects the correct values if there's a match between both tables, and after that grouping it by month? I can use the first query and do the grouping in PHP afterwards, but I'd like to get the right results straight from MySQL if that's possible.
MySQL SELECT with LEFT JOIN and GROUP problem
===

I have a main table <b>foo</b> with dates and values, and a table <b>bar</b> with exception dates and values. If the date exists in the <b>bar</b> table, that value applies, otherwise the default <b>foo</b> value. So, for example:

<pre>
<b>foo</b>
id  date        value
1   2009-11-19  25
2   2009-11-20  50

<b>bar</b>
id  date        value
1   2009-11-19  50
</pre>

To select the right values I use the following type of query:
<code><pre>
SELECT
  f.date,
  IF (f.date = b.date, b.value, f.value) AS value
FROM foo f
LEFT JOIN bar b
  ON b.date = f.date
</pre></code>

This works fine. The date "2009-11-19" exists in <b>bar</b>, so it selects the 50-value. But now I'd like to GROUP the results by MONTH, using this query:
<code><pre>
SELECT
  MONTH(f.date) AS month,
  IF (f.date = b.date, b.value, f.value) AS value
FROM foo f
LEFT JOIN bar b
  ON b.date = f.date
GROUP BY month
</pre></code>

It now returns the results by month, so the grouping works fine. However, it now ignores the <b>bar</b> values, and it seems it doesn't do any matching at all. The total for the month is 75 (25 from foo + 50 from foo) instead of 100 (50 from bar + 50 from foo).

Is there a way to make this work? So that it selects the correct values if there's a match between both tables, and after that grouping it by month? I can use the first query and do the grouping in PHP afterwards, but I'd like to get the right results straight from MySQL if that's possible.