title: MySQL join on 2 tables
body: <p>I need to do a search on 2 simultaneous tables, and I thought that this join would work but its giving me an incorrect syntax error.</p>
  
  <pre><code>$return_arr = array();
      $query = mysql_query("SELECT * FROM clients WHERE lastname LIKE '$q%' AND agencyid = '$agencyid'
                            UNION
                            SELECT * FROM busclients WHERE busname LIKE '$q%' AND agencyid = '$agencyid'")or die(mysql_error());
              if($query) {
                  while ($result = mysql_fetch_array($query)) {
                      if(isset($result['busname'])){
                          $description['id'] = $result['ID'];
                      $description['value'] = $result['busname'] ;
                      array_push($return_arr,$description);
                      }
                      else
                      {
                      $description['id'] = $result['ID'];
                      $description['value'] = $result['lastname'] . ", " . $result['firstname'] ;
                      array_push($return_arr,$description);    
                      }
  
                      }
                  }
  echo json_encode($return_arr);
  </code></pre>
  
  <p><em>Edited with fix suggested below and entire syntax</em></p>
  
  <p>This is a query from an autocomplete search box. So when someone types in a client or business client name, it uses this query to search the database and then displays the results using jquery. </p>
  
  <p>The fix below works but when I do a search on a business client it is returning []. A client search works fine.</p>