title: Query to get select data inside query using Grouped By
body: <p>I have a not so simple (maybe simple) MySQL query question.</p>
  
  <p>I am trying to get results like so:</p>
  
  <p>[users][disabled_users][venue_name]</p>
  
  <p>So results would be like so:</p>
  
  <p>5, 2, AABB</p>
  
  <p>2, 0, ABCC</p>
  
  <p>The results I am getting are:</p>
  
  <p>5, 2, AABB</p>
  
  <p>2, 2, ABCC &lt;-- Issue is it finds the 2 results regardless</p>
  
  <p>Here is my current query:</p>
  
  <pre><code>SELECT
  count(t.uid) as users, /* GET COUNT OF ACTIVE USERS GROUPED BY VENUE ID*/ 
  t3.vid as venue_id /* SOLUTION */   
  (
      SELECT sum(t1.uid) as users /* GET COUNT OF DISABLED USERS GROUPED BY VENUE ID */
      FROM t1
      JOIN t2 ON (t1.sid = t2.id)
      JOIN t3 ON (t2.cid = t3.id)
      WHERE t1.tid = 3 AND t3.vid = venue_id /* SOLUTION */
      GROUP BY t3.vid
  ) as disabledUsers
  FROM t1
  JOIN t2 ON (t1.sid = t2.id)
  JOIN t3 ON (t2.cid = t3.id)
  WHERE t1.tid = 2
  GROUP BY t3.vid;
  </code></pre>
  
  <p>EDIT: The solution is marked by the /* SOLUTION */ I added two lines one selecting the venue id (vid) giving it an alias of venue_id and adding an extra condition in my inner select.</p>