title: where clause while joining select
body: <p>I need to get payment sum for all period and for current month. There are two tables: category and transactions. </p>
  
  <p>transactions:</p>
  
  <pre><code>id  int(11)                         
  category    varchar(32)                          
  dttm_added  datetime                    
  minus   float               
  minus_currency  varchar(32)
  </code></pre>
  
  <p>categories:</p>
  
  <pre><code>id  int(11)                 
  key varchar(32)                          
  name    varchar(50)                          
  type    varchar(1)
  </code></pre>
  
  <p>Here is my query:</p>
  
  <pre><code>select  `key`, `id`, `name`, minus_month,month_cur
                                  from `categories` as ct
  
                                  left join (
                                  select  `category` as tr_ct_m, date_format(`dttm_trans`, '%Y%m') as dat, sum(`minus`) as minus_month, `minus_currency` as month_cur from `transactions`  where dat = date_format(now(), '%Y%m')
                                  ) as tr_m on tr_m.tr_ct_m = ct.key 
                                  where `type` = '-'
  </code></pre>
  
  <p>I need to check clause in select before joining, because after sum  of minus_month all dates are turning to Null.
  Help plz                                   </p>