MySQL date query only returns one year, when multiple exist

Posted by Bowman on Stack Overflow See other posts from Stack Overflow or by Bowman
Published on 2010-04-19T18:39:33Z Indexed on 2010/04/19 18:43 UTC
Read the original article Hit count: 254

Filed under:
|
|
|
|

I'm a part-time designer/developer with a part-time photography business. I've got a database of photos with various bits of metadata attached. I want to query the database and return a list of the years that photos were taken, and the quantity of photos that were taken in that year.

In short, I want a list that looks like this:

2010 (35 photos)
2009 (67 photos)
2008 (48 photos)

Here's the query I'm using:

SELECT YEAR(date) AS year, COUNT(filename) as quantity FROM photos WHERE visible='1' GROUP BY 'year' ORDER BY 'year' DESC

Instead of churning out all the possible years (the database includes photos from 2010-2008), this is the sole result:

2010 (35 photos)

I've tried a lot of different syntax but at this point I'm giving in and asking for help!

© Stack Overflow or respective owner

Related posts about mysql

Related posts about query