MySQL Forums
Forum List  »  Newbie

Re: Return 0 for data with no matching values
Posted by: Dean Richert
Date: March 24, 2015 07:09PM

I had to change the query a little bit to get it to work (birthday to birthdates), but it did work:

select c.yr, count(d.birthday)
from (select distinct year(dates) yr from calendar) c
left join birthdates d on c.yr=year(d.birthday)
group by c.yr;

I also found that if you don’t alias birthdates to ‘d’, it still works, but you have to be more verbose in other places:

select c.yr, count(birthdates.dates)
from (select distinct year(dates) yr from calendar) c
left join birthdates on c.yr=year(birthdates.dates)
group by c.yr;


Thank you. After several days of trying you have really helped me out.

Options: ReplyQuote




Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.