I have a query that is basically this:
SELECT count(*)
FROM table1 as t1
LEFT JOIN table2 as t2 on t2.foo=t1.foo
group by t1.bar
The basic information is in table 1, but I need additional information from table 2. The problem is that there may be more than one row in table 2 with the same "foo". The difference is that only one item would be flagged as active.
I can't just do WHERE t2.status=1 (active) because this is a historical report and we may need to count those that are inactive.
I also can't change the field that I group by because even though I am joining on one field, I need it grouped by "bar".
Is there any way to change the join statement so that it will always only pull one record from table 2? If there is more than one, it should only pull the active one.
Thanks to anyone who is willing to tackle this one...