title: SQL Server: How do I check whether records exist for each group in a list of groups?
body: <p>I have a TableA:</p>
  
  <pre><code>TeamID PersonID
   ...   ...
   1     100
   2     101
   2     105
   2     444
   3     501
   ...   ...
  </code></pre>
  
  <p>Also TableB </p>
  
  <pre><code>PersonID CourseID
  ...      ...
  444      c103
  444      c2048
  101      c3214
  ...      ...
  </code></pre>
  
  <p>How do I write a simple query such that, for example, I can find whether each person in Team 2 has at least one CourseID associated in TableB. The result for my example is:  </p>
  
  <pre><code>TeamID PersonID HasCourse
   2     101      1
   2     105      0
   2     444      1
  </code></pre>
  
  <p>The shorter the query the better, ideally not using loops. </p>