title: MySQL Left Join Subquery with *
body: <p>I'm putting together a fairly simple query with a subquery in the JOIN statement. It only works if I include an * in the subquery select. Why?</p>
  
  <p>This works</p>
  
  <pre><code>$sql = 'SELECT locations.id, title, name, hours.lobby
          FROM locations
          LEFT JOIN states ON states.id = locations.state_id
          LEFT JOIN (SELECT *, type_id IS NOT NULL AS lobby FROM location_hours) AS hours ON locations.id = hours.location_id
          GROUP BY locations.id';
  </code></pre>
  
  <p>This doesn't</p>
  
  <pre><code>$sql = 'SELECT locations.id, title, name, hours.lobby
          FROM locations
          LEFT JOIN states ON states.id = locations.state_id
          LEFT JOIN (SELECT type_id IS NOT NULL AS lobby FROM location_hours) AS hours ON locations.id = hours.location_id
          GROUP BY locations.id';
  </code></pre>
  
  <p>Should I even be doing it this way? I thought * was not best if you don't need all the fields?</p>