title: left join table and get date range per each table
body: <p>i have the following query:</p>
  
  <pre><code>    SELECT 
         t.aff_id,
         Ifnull(t.campaign_name, "direct") AS campaign_name,
         Count(t.uuid)                     AS visits,
         Count(DISTINCT l.trader_id)       AS leads
  FROM   trackings AS t
         LEFT JOIN (SELECT uuid,
                           trader_id
                    FROM   leads
                    WHERE  aff_id = "1"
                           AND created_at BETWEEN "2015-05-01 00:00:00" AND
                                                  "2015-05-20 23:59:59") AS l
                ON l.uuid = t.uuid
  
  WHERE  `t`.`created_at` BETWEEN '2015-05-01 00:00:00' AND '2015-05-20 23:59:59'
         AND `t`.`aff_id` = '1'
  GROUP  BY `t`.`campaign_name` 
  </code></pre>
  
  <p>the leads table date range has no effect, what should be the correct structure for such a query?
  <a href="http://sqlfiddle.com/#!9/5d125/2" rel="nofollow">http://sqlfiddle.com/#!9/5d125/2</a> </p>