title: mysql Query Optimization with inner join
body: <p>I have a query</p>
  
  <pre><code>$query = "SELECT DISTINCT report_date,weekreportDate FROM contract_sales a 
      INNER JOIN contract b ON a.contract_UUID = b.UUID
      INNER JOIN geoPoint c ON b.customer_UUID = c.customerUUID
      WHERE c.com_UUID = '$com' AND a.report_date &gt;= Date('$dateafter')
      AND c.city_UUID = '$cit' ORDER BY `report_date`";
  </code></pre>
  
  <p>What I need to do is first get rid of all the results via date filtering but as you can see I get everything and then do my date sorting in the checks..</p>
  
  <p>I am inner join all of them - is there a better way to do this? </p>
  
  <p>I have a report for each date - and have two years of data - I want to get only dates in 2014 so as you can see I have 700+ dates that are useless to me right away but I have to go through all of them can check the other string UUID as well... what can I do to speed up my (working - albeit slow implementation)?</p>
  
  <p>Explain information as requested:</p>
  
  <pre><code>Generation Time: Feb 20, 2014 at 06:48 PM
  Generated by: phpMyAdmin 3.3.10.4 / MySQL 5.1.53-log
  SQL query: EXPLAIN SELECT DISTINCT report_date,weekreportDate FROM contract_sales a INNER JOIN contract b ON a.contract_UUID = '1234' INNER JOIN geoPoint c ON b.customer_UUID = '1234' WHERE c.com_UUID = '1234' AND a.report_date &gt;= Date('2014-01-01') AND c.city_UUID = '1234' ORDER BY `report_date`; 
  Rows: 3
  
  id  select_type table   type    possible_keys   key key_len ref rows    Extra
  1   SIMPLE  a   ref uuid_conlcs uuid_conlcs 110 const   1   Using where; Using temporary; Using filesort
  1   SIMPLE  b   ref uuid_cust   uuid_cust   110 const   1   Using where; Using index; Distinct
  1   SIMPLE  c   ref uuid_gargp,uuid_citgp   uuid_citgp  110 const   1   Using where; Distinct
  </code></pre>