title: SQL Display results only if the row exists in another table
body: <p>Is there a way to display results only if that particular value exists, if there are multiple entries of it in another table?</p>
  <p>For example, I am trying to display teacher name only if the type is Math. If there are no entries of Math, the column Teacher should display none.</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>UserName U</th>
  <th>Email</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>Me</td>
  <td>row@1.com</td>
  </tr>
  <tr>
  <td>Wiz</td>
  <td>bow@1.com</td>
  </tr>
  </tbody>
  </table>
  </div><div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Classes C</th>
  <th>Username</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>First</td>
  <td>Me</td>
  </tr>
  <tr>
  <td>Second</td>
  <td>Me</td>
  </tr>
  <tr>
  <td>Third</td>
  <td>Me</td>
  </tr>
  <tr>
  <td>Third</td>
  <td>Wiz</td>
  </tr>
  </tbody>
  </table>
  </div><div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>Classes</th>
  <th>Teacher T</th>
  <th>Type</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>First</td>
  <td>A</td>
  <td>Math</td>
  </tr>
  <tr>
  <td>Second</td>
  <td>B</td>
  <td>Math</td>
  </tr>
  <tr>
  <td>Third</td>
  <td>C</td>
  <td>NULL</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>Final result as Math Classes exist for Me</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>UserName</th>
  <th>Email</th>
  <th>Teacher</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>Me</td>
  <td>row@1.com</td>
  <td>A</td>
  </tr>
  <tr>
  <td>Me</td>
  <td>row@1.com</td>
  <td>B</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>Final result as Math Classes exist for Wiz with no math classes</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th>UserName</th>
  <th>Email</th>
  <th>Teacher</th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>Wiz</td>
  <td>bow@1.com</td>
  <td>None</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>The issue I'm running into is that my query is displaying either no entries even though user has no math but has other classes, or it's displaying Math and None at the same time.</p>
  <p>My current query is as follows:</p>
  <pre><code>from User u
  join classes c on c.username=u.username
  join teachers t on t.classes=c.classes and type ='Math' &lt;---- If I left join, I get 2 entries, if I join, I get 0 entries for non-math folks
  where username ='Me' 
  </code></pre>
  <p>So the 3 scenarios I want the query to cover:</p>
  <ol>
  <li><p>If user does not exist in the user table (no entry)</p>
  </li>
  <li><p>If user exists but doesn't have any math (show user None entry)</p>
  </li>
  <li><p>If user exists and has math (regardless of any other type) display classes - final situation up there</p>
  </li>
  </ol>
  <p>Do I do some kind of select count in the case statement? This query is part of a bigger execution query.</p>
  <p>This was SQL Server Management Studio</p>