title: How to get most popular name by year in SQL Server
body: <p>I am practicing SQL in Microsoft SQL Server 2012 (not a homework question), and have a table <code>Names</code>. The table shows baby names by year, with columns <code>Sex</code> (gender of name), <code>N</code> (number of babies having that name), <code>Yr</code> (year), and <code>Name</code> (the name itself). </p>
  
  <p>I need to write a query using only one <code>SELECT</code> statement that returns the most popular baby name by year, with gender, the year, and the number of babies named. So far I have;</p>
  
  <pre><code>SELECT *
  From Names
  ORDER By N DESC;
  </code></pre>
  
  <p>Which gives the highest values of N in DESC order, repeating years. I need to limit it to only the highest value in each year, and everything I have tried to do so has thrown errors. Any advice you can give me for this would be appreciated.</p>