title: MySQL LEFT JOIN with optional value in second table
body: <p>I have two tables: <code>projects</code> and <code>user_licenses</code>. </p>
  
  <p>I'd like to grab the entire list of projects from the database, as well as the user's current license state. The licenses table has a user ID field which I check against a <code>$_SESSION</code> variable for the value. The thing is, they might not have a license, or a non-logged in visitor may want to see the projects list. My question is this: How can I get the data from the left table <em>always</em> display, but only grab data for that row from the right table when certain conditions are met? </p>
  
  <p>The query I have at the moment is this:</p>
  
  <pre><code>   SELECT Projects.*, 
            UserLicenses.* 
       FROM Projects 
  LEFT JOIN UserLicenses ON Projects.id = UserLicenses.project_id 
      WHERE UserLicenses.user_id = 12 
   ORDER BY name ASC
  </code></pre>