title: MySQL: Using JOINS with WHERE clause to get all records from one table and available records from the other
body: <p>I am tryin to run a SQL query as below</p>
  <pre><code>SELECT organization.idorganization,
  organization.name,
  organization.image_url,
  organization.website,
  organization.description,
  organization.phone,
  organization.email,
  organization.spare_parts_items,
  organization.specialty_vehicles,
  organization.on_the_spot_service,
  organization.home_visits,
  organization.latitude,
  organization.longitude,
  organization.no_of_views,
   organization.is_disabled,
  organization.date_created,
  organization.last_update,
  organization.address,
  cover_photo.idcover_photo,
  cover_photo.image_url,
  cover_photo.thumbnail,
  ( 6371 * acos( cos( radians(7.294324) ) * cos( radians( organization.latitude ) ) * cos( radians( organization.longitude ) - radians(80.646185) ) 
  + sin( radians(7.294324) ) * sin( radians( organization.latitude ) ) ) ) AS distance 
  FROM organization 
  LEFT OUTER JOIN cover_photo ON cover_photo.idcover_photo = organization.idorganization
  WHERE organization.idorganization_type =1 HAVING distance &lt; 20 AND cover_photo.thumbnail=true
  </code></pre>
  <p>Here, my expectation is to get all records from <code>organization</code> whether it has <code>cover_photo</code>s or not. Thats why I have used a <code>LEFT OUTER JOIN</code>. But, if it has <code>cover_photo</code>s, it should get only those which is a <code>thumbnail</code>. The <code>cover_photo</code> contains more than one photo for each <code>organization</code>.</p>
  <p>When I run my code, I do not get what I am looking for. If there is no <code>thumbnails</code> available in <code>cover_photo</code> table, that particular <code>organization</code> is completely ignored. At this moment I have no <code>cover_photo</code> for any organization, so what I get is no results.</p>
  <p>How to fix this?</p>