title: Mysql left join to get unique topics
body: <p>I have two tables:</p>
  
  <p>Topic table:</p>
  
  <pre><code>topic_id
  2
  3
  4
  </code></pre>
  
  <p>like table:</p>
  
  <pre><code>topic_id         user_id
  2                4
  2                6
  3                1
  4                2
  </code></pre>
  
  <p>For a logged in user (use $user_id to represent), I need to return unique topics and a flag to indicate whether this user has liked this post or not.
  For the above example, if the user id for the logged in user is 2, the return should be:</p>
  
  <pre><code>topic_id        liked
  2               0 or NULL
  3               0 or NULL
  4               1
  </code></pre>
  
  <p>I have tried to leftJoin topic and like table with "like.user_id = $user_id OR like.user_id is NULL", but that will left out topics that have likes but haven't liked by the user. Could anyone help me with the query? Thanks very much.</p>