title: SQL: Using outer join in SQL Server 2012
body: <p>I'm trying to learn how to use the OUTER JOIN function in SQL Server, so that the select query returns all values from two tables, even the unmatched ones.</p>
  
  <p>Here are the two sample tables I'm using (Boys and Girls):  </p>
  
  <pre><code>Boys:
  
  Name    City
  Andrew  Cape Town
  Mike    Paphos
  Simon   Amsterdam
  
  Girls:
  
  Name    City
  Georgia Paphos
  Megan   London
  Eva     Amsterdam
  Stephi  Cape Town
  </code></pre>
  
  <p>Here is the query I've written:</p>
  
  <pre><code>SELECT boys.name, boys.city, girls.name, girls.city
      FROM boys, girls
      RIGHT OUTER JOIN boys as men ON boys.city=girls.city; 
  </code></pre>
  
  <p>I'm trying to return a table as follows:</p>
  
  <pre><code>boys.Name     boys.City        girls.name        girls.city    
  Andrew        Cape Town        Stephi            Cape Town  
  Mike          Paphos           Georgia           Paphos  
  Simon         Amsterdam        Eva               Amsterdam  
  NULL          NULL             Megan             London  
  </code></pre>
  
  <p>A normal inner join ignores the last line because it doesn't have a matching boy city.</p>
  
  <p>Could anyone help me with this?</p>
  
  <p>Thanks!</p>
  
  <p>Mike</p>