I want to return a row for every month in a range specified- what I’m having trouble with is- that if I do not have a row there is nothing returned; What i was want is the month name to be returned and winner_id to be null
my query so far.
SELECT MONTHNAME(dated) as Month, winner_id FROM competitions WHERE dated > '2012-01-01'
What i want my output to look like is
Month Winner_id
-------------------
January NULL
February 2654
March 19864
April NULL
the problem is i do not have a row for january or april in the db- but i still want a month returned?
should i do the months in php and do individual queries for each month?
There are ways to do this in MySql but it would be overkill in your case. I’d use a variation of your current query and fill the gaps in php: