AMENDED 24/11/2012 based on comments below.
I have a MySQL database (v5.0.95) of members which lists when they joined
CREATE TABLE IF NOT EXISTS `members` (
`id` int(11) NOT NULL,
`group_id` int(11) NOT NULL,
`name` varchar(64) NOT NULL,
`joined` datetime NOT NULL,
KEY `id` (`id`),
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
I also have a second table which will have records indicating which YYYY-MM
CREATE TABLE IF NOT EXISTS `blocker` (
`group_id` int(11) NOT NULL,
`YYYYMM` char(7) NOT NULL
) ENGINE=MyISAM DEFAULT CHARSET=latin1;
Ideally the following join would provide the following
SELECT date_format( m.joined, '%Y-%m' ) AS DateJoined, count( * ) AS NumJoined
FROM members AS m
LEFT OUTER JOIN blocker AS b
ON b.YYYYMM = date_format( m.joined, '%Y-%m')
WHERE m.group_id =1637017 AND b.group_id =1637017
GROUP BY DateJoined
ORDER BY DateJoined ASC
would give me this
DateJoined NumJoined
2012-01 0
2012-02 0
2012-03 0
2012-04 17
2012-05 0
2012-06 12
2012-07 10
2012-08 10
2012-09 11
2012-10 14
2012-11 4
unfortunately it is not providing zero result months and gives me this
DateJoined NumJoined
2012-04 17
2012-06 12
2012-07 10
2012-08 10
2012-09 11
2012-10 14
2012-11 4
Any pointers would be appreciated. Am I close...?