title: SQL return row from first table, and then joined tables separately
body: <p>I have two tables. I want to select all rows from table 1, and any rows from table 2 that share the same id. I need to return the row from table 1, and then, if they exist, separately return the joined rows of both table 1 and 2. My current code below returns the row from table 1 if there is no match in table 2. However, if a match exists in table 2 it will only return the joined rows.</p>
  
  <pre><code>SELECT
      table1.id,
      COALESCE(table2.name, table1.name) AS name
  FROM
      table1
  LEFT JOIN
      table2
  ON
      table1.id = table2.id
  WHERE
      table1.stock = 0
  </code></pre>
  
  <p>And here's what I'm after:</p>
  
  <pre><code>**Table 1**
  id  | name  | stock
  101 | sock  | 4
  102 | hat   | 0
  103 | belt  | 0
  
  **Table 2**
  id  | name
  101 | banana
  102 | pear
  102 | apple
  
  **Query output**
  id  | name
  102 | hat
  102 | pear
  102 | apple
  103 | belt
  </code></pre>