title: Sql Nested group by
body: <p>Following query returns a number of people having the same name with gender = Male.</p>
  
  <pre><code>select  lookup_name.firstname,count(lookup_name.firstname)
  from lookup_name
  where gender='M'
  group by firstname
  </code></pre>
  
  <p>similarly, the query below returns a number of people having the same name with gender = Female.</p>
  
  <pre><code>select  lookup_name.firstname,count(lookup_name.firstname)
  from lookup_name
  where gender='F'
  group by firstname
  </code></pre>
  
  <p>I need to write a query which finds out the name and tell the gender (whether male or female) with the greater count. i.e higher probability of that name in the database is of being male or female?</p>