title: Unknown Column in 'IN/ALL/ANY' subquery
body: <p>I've got 2 tables: members and member_logs.  </p>
  
  <p>Members can belong to groups, which are in the members table.  Given a date range and a group I'm trying to figure out how to get the 10 days with the highest number of successful logins.  What I have so far is a massive nest of subquery terror.</p>
  
  <pre><code>SELECT count(member_id) AS `num_users`,
  DATE_FORMAT(`login_date`,'%Y-%m-%d') AS `reg_date` 
  FROM member_logs 
  WHERE `login_success` = 1 
  and `reg_date` IN 
      (SELECT DISTINCT DATE_FORMAT(`login_date`,'%Y-%m-%d') AS `reg_date` 
       FROM member_logs 
       WHERE `login_success` = 1 
       and (DATE_FORMAT(`login_date`,'%Y-%m-%d') BETWEEN '2012-02-25' and '2014-03-04'))
  and `member_id` IN 
      (SELECT `member_id` 
       FROM members 
       WHERE `group_id` = 'XXXXXXX' 
       and `deleted` = 0) 
  ORDER BY `num_users` desc 
  LIMIT 0, 10
  </code></pre>
  
  <p>As far as I understand what is happening is that the WHERE clause is evaluating before the subqueries generate, and that I also should be using joins.  If anyone can help me out or point me in the right direction that would be incredible.</p>
  
  <p>EDIT: Limit was wrong, fixed it</p>