title: Column is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause
body: <p>I'm trying to return a table with the depth of a node in a hierarchy represented using the nested set model, I'm following this tutorial but the query used in the section 'Finding the depth of Nodes' doesn't work for me: <a href="http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/" rel="nofollow">http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/</a>   </p>
  
  <pre><code>SELECT node.GroupName, (COUNT(parent.GroupName) - 1) AS depth
  FROM CompanyGroup AS node,
          CompanyGroup AS parent
  WHERE node.LeftID BETWEEN parent.LeftID AND parent.RightID
  GROUP BY node.GroupName
  ORDER BY node.LeftID;
  </code></pre>
  
  <p>Running this query I get the error "<em>Column 'CompanyGroup.GroupName' is invalid in the select list because it is not contained in either an aggregate function or the GROUP BY clause.</em>"</p>
  
  <p>Can anyone explain why please?</p>
  
  <p>Edit: wrong column in the error message, my apologies the error is: "<em>Column "CompanyGroup.LeftID" is invalid...</em>"</p>