List:General Discussion« Previous MessageNext Message »
From:Gerald Clark Date:January 7 2002 8:16pm
Subject:Re: Count() does not count correctly?
View as plain text  

Jens Mildner wrote:

> Hello MySQL-users !
> 
> Houston, I've got a problem here.
> 
> I'm running the following query from a PHP-Script:
> 
> SELECT years.year AS yearlist, count(years.year) AS gamecount 
> 
> FROM years 
> 
> LEFT JOIN games 
> 
> ON years.year = games.release_year
> 
> GROUP BY years.year 
> 
> ORDER BY gamecount DESC, yearlist
> 
> 
> This query should do the following: 
> 
> Every year from years.year should be returned along with the 
> number of games that have been released in that year sorted by 
> the gamecount.
> years.year and games.release_year both do NOT contain NULL.
> 
> The problem is the following:
> 
> Years in which no games were released are returned with a 
> gamecount of 1. Why that??? All other years with games released 
> in it are getting the correct gamecount.
> 
> Please help me.
> 
> Greetings from Germany, Jens Mildner.

Either don't  use a left join, or add  "WHERE games.release_year IS NOT 
NULL"


> 

Thread
Count() does not count correctly?Jens Mildner7 Jan
  • Re: Count() does not count correctly?Gerald Clark7 Jan
  • Re: Count() does not count correctly?Rodney Broom7 Jan
RE: Count() does not count correctly?Tom Haapanen7 Jan