title: How to UNION ALL two SELECT statements?
body: <p>I have 2 tables, one looks like this:</p>
  
  <p>TABLE ONE</p>
  
  <pre><code>id | Last Name | First Name | Username | Password | Secret Question
  </code></pre>
  
  <p>and another that looks like this:</p>
  
  <p>TABLE TWO</p>
  
  <pre><code>id | Hobby | Country | 
  </code></pre>
  
  <p>I want to combine a Select statement that grabs data from both tables and output the results. The following code:</p>
  
  <pre><code>$select = mysql_query("
  
      SELECT * FROM table_one WHERE Username = 'Bob'
  
      UNION ALL
  
      SELECT * FROM table_two WHERE Hobby = 'Baseball'
  
  ");
  
  while ($return = mysql_fetch_assoc($select)) {
  
  $userName = $return['Username'];
  
  $hobby = $return['Hobby'];
  
  }
  
  echo "$userName likes $hobby";
  </code></pre>
  
  <p>results in a <strong>The used SELECT statements have a different number of columns</strong> error, what am I doing wrong?</p>
  
  <hr>
  
  <p>EDIT:</p>
  
  <p>Running this gives the following error: <strong>Warning: mysql_fetch_assoc(): supplied argument is not a valid MySQL result resource in /home/studentw/public_html/foo.php on line 16</strong></p>
  
  <pre><code>$select = mysql_query("
  
  SELECT FROM TABLE_ONE t1
    INNER JOIN TABLE_TWO t2
      ON t1.id = t2.id
  WHERE t1.Username = 'Bob'
    AND t2.Hobby = 'Baseball'
  
  ");
  
  while ($return = mysql_fetch_assoc($select)) {
  
      $firstName = $return['Username'];
      $hobby = $return['Hobby'];
  
  }
  
  echo "$firstName likes $hobby";
  </code></pre>
  
  <p>The values in the tables are:</p>
  
  <p>TABLE ONE</p>
  
  <pre><code>id | Last Name | First Name | Username | Password | Secret Question
  
   1 | Hughes | Bobby | Bob | 123 | Maiden name?
  </code></pre>
  
  <p>TABLE TWO</p>
  
  <pre><code>id | Hobby | Country | 
  
   1 | Baseball | USA
  </code></pre>