title: SQL Query to return maximums over decades
body: <p><strong>THIS IS USING MYSQL</strong>
  My question is the following. I have a baseball database, and in that baseball database there is a master table which lists every player that has ever played. There is also a batting table, which tracks every players' batting statistics. I created a view to join those two together; hence the <code>masterplusbatting</code> table. 
    I now want to find the highest HR hitter in each decade since baseball began. Here is what I tried.</p>
  
  <pre><code>    select f.yearID, truncate(f.yearid/10,0) as decade,f.nameFirst, f.nameLast, f.HR
      from (
      select yearID, max(HR) as HOMERS
      from masterplusbatting group by yearID
      )as x inner join masterplusbatting as f on f.yearID = x.yearId and f.HR = x.HOMERS
      group by decade
  </code></pre>
  
  <p>You can see that I truncated the yearID in order to get <code>187, 188, 189</code> etc instead of <code>1897, 1885,</code>. I then grouped by the decade, thinking that it would give me the highest per decade, but it is not returning the correct values. For example, it's giving me Adrian Beltre with 48 HR's in 2004 but everyone knows that Barry Bonds hit 73 HR in 2001. Can anyone give me some pointers?</p>