title: How can optimize these instruction with MYSQL (subqueries for each row)?
body: <p>My problem is that we make a select, and then, for each row, we run 4 differents request SQL (is madness), as you can guess we make a lot of requests, and the system using this is very slow.</p>
  
  <pre><code>SELECT 
      deal_source.id, 
      deal_source.source_name, 
      deal_source.spider_status, 
      spider.last_success_date
  FROM deal_source 
  JOIN spider 
  ON deal_source.id = spider.deal_source_id
  </code></pre>
  
  <p>Then for each row of this query we make:</p>
  
  <pre><code>$total_query = "SELECT count(id) as total
                  FROM spider_log 
                  WHERE deal_source_id = '$deal_source_id' 
                  AND date_format(date_created, '%Y-%m-%d') = '$lastdate' ";
  
  $added_query = "SELECT count(id) as added
                  FROM spider_log 
                  WHERE deal_source_id = '$deal_source_id' 
                  AND action = 'added'  
                  AND date_format(date_created, '%Y-%m-%d') = '$lastdate' ";
  
  $extended_query = "SELECT count(id) as extended 
                     FROM spider_log 
                     WHERE deal_source_id = '$deal_source_id' 
                     AND action = 'extended'  
                     AND date_format(date_created, '%Y-%m-%d') = '$lastdate' ";
  
  $duplicate_query = "SELECT count(id) as duplicate 
                      FROM spider_log 
                      WHERE deal_source_id = '$deal_source_id' 
                      AND action = 'duplicate'  
                      AND date_format(date_created, '%Y-%m-%d') = '$lastdate' ";
  </code></pre>