Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

Need to get max date for each year from list of arbitrary dates:

date         year
1/10/2013    2013
3/26/2013    2013
4/20/2012    2012
9/10/2012    2012
5/6/2011     2011

So with a working query, using the above data, the correct result would be:

maxdate     year
3/26/2013    2013
9/10/2012    2012
5/6/2011     2011

Our database is proprietary, supporting only ANSI-SQL, no fancy extensions. Tried using group_by, but it's retrieving all dates for each year, not what I want.

share|improve this question
up vote 3 down vote accepted

It is possible that I am missing something, but you should be able to get the result easily using the max() aggregate and a GROUP BY:

  max(date) maxdate,
from yourtable
group by year;

See SQL Fiddle with Demo

share|improve this answer
I was grouping by date, that was the issue, ty. – Raffian Dec 10 '13 at 17:52

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.