title: How to get the value of max() group when in subquery?
body: <p>So i woud like to find the department name or department id(dpmid) for the group that has the max average of age among the other group and this is my query:</p>
  
  <pre><code>select 
   MAX(avg_age) as 'Max average age' FROM (
      SELECT 
        AVG(userage) AS avg_age FROM user_data GROUP BY 
           (select dpmid from department_branch where 
              (select dpmbid from user_department_branch where 
                 user_data.userid = user_department_branch.userid)=department_branch.dpmbid)
  ) AS query1
  </code></pre>
  
  <p>this code show only the max value of average age and when i try to show the name of the group it will show the wrong group name.</p>
  
  <p>So, How to show the name of max group that has subquery from another table???</p>