title: SQL query - get the max of all counts
body: <p>I have an airport database:</p>
  
  <p><a href="https://i.stack.imgur.com/vGFP0.jpg" rel="nofollow noreferrer">Airpot Database</a></p>
  
  <p>and I need to display the pilot ID of the pilot who flew the most times, this is my query:</p>
  
  <pre><code>SELECT 
      t.PilotID, MAX(t.flights) 
  FROM 
      (SELECT 
           PilotID, COUNT(*) AS flights  
       FROM 
           Flights 
       GROUP BY 
           PilotID) AS t
  </code></pre>
  
  <p>without the <code>t.pilotID</code>, it works and shows only the max flights - but with
  the <code>t.pilotID</code> I get this error:</p>
  
  <blockquote>
    <p>You tried to execute a query that does not include the specified expression "PilotID" as part of an aggregate function</p>
  </blockquote>