title: Subquery in SELECT or Subquery in JOIN?
body: <p>I have a MYSQL query of this form:</p>
  
  <pre><code>SELECT
      employee.name,
      totalpayments.totalpaid
  FROM
      employee
      JOIN (
          SELECT
              paychecks.employee_id,
              SUM(paychecks.amount) totalpaid
          FROM
              paychecks
          GROUP BY
              paychecks.employee_id
           ) totalpayments on totalpayments.employee_id = employee.id
  </code></pre>
  
  <p>I've recently found that this returns MUCH faster in this form:</p>
  
  <pre><code>SELECT
      employee.name,
      (
          SELECT
              SUM(paychecks.amount)
          FROM
              paychecks
          WHERE
              paychecks.employee_id = employee.id
      ) totalpaid
  FROM
      employee
  </code></pre>
  
  <p>It surprises me that there would be a difference in speed, and that the lower query would be faster.  I prefer the upper form for development, because I can run the subquery independently.</p>
  
  <p>Is there a way to get the "best of both worlds": speedy results return AND being able to run the subquery in isolation?</p>