title: Trying to use UNION ALL to INSERT into temporary table
body: <p>I'm trying to setup a basic search script. It was suggested to insert data from current mysql tables into a temp table to speed the search up. </p>
  
  <p>Here is the code I've got so far:</p>
  
  <pre><code>$temp = 'search_' . date('YmdHis'); // name your temp table
  
  $sql = "CREATE TEMPORARY TABLE IF NOT EXISTS {$temp} (
        `id` INT UNSIGNED NOT NULL AUTO_INCREMENT PRIMARY KEY,
        `Model` varchar(255) default NULL,
        `Make` varchar(255) default NULL,
        `Year` varchar(255) default NULL,
        `Loc.` varchar(255) default NULL,
        `Sale Price` varchar(255) default NULL,
        `Serial No.` varchar(255) default NULL,
        `Stock No.` varchar(255) default NULL,
        `Tag No.` varchar(255) default NULL,
        `Comments` varchar(255) default NULL,
        `Description` varchar(255) default NULL,
        FULLTEXT KEY `Model` (`Model`,`Make`,`Year`,`Loc.`,`Sale Price`,`Serial No.`,`Stock No.`,`Tag No.`,`Comments`,`Description`)
       )";
  
  $sql .= "INSERT INTO $temp (
          id,
          Model,
          Make,
          Year,
          `Loc.`,
          `Sale Price`,
          `Serial No.`,
          `Tag No.`,
          Comments,
          Description
          )
  
          (
          (SELECT null,`Model`,`Make`,`Year`,`Loc.`,`Sale Price`,`Serial No.`,`Stock No.`,`Tag No.`,`Comments`,`Description` FROM ag_auger_and_grain_handling WHERE Status='IN' or Status='OF'
              UNION ALL
          SELECT null,`Model`,`Make`,`Year`,`Loc.`,`Sale Price`,`Serial No.`,`Stock No.`,`Tag No.`,`Comments`,`Description` FROM ag_combine WHERE Status='IN' or Status='OF'
              UNION
          SELECT null,`Model`,`Make`,`Year`,`Loc.`,`Sale Price`,`Serial No.`,`Stock No.`,`Tag No.`,`Comments`,`Description` FROM ag_tractor WHERE Status='IN' or Status='OF')
          )
      )";
  
  ?&gt;
  </code></pre>
  
  <p>Here is the error I'm receiving:</p>
  
  <blockquote>
    <p>Could Not Perform Query Because: You have an error in your SQL syntax;
    check the manual that corresponds to your MySQL server version for the
    right syntax to use near 'INSERT INTO search_20121215094411 ( id,
    Model, Make, Year, <code>Loc.</code>, `' at line 14</p>
  </blockquote>
  
  <p>I can only guess it has something to do with the unconventional column names (Loc., Sale Price, etc.). These were set by a previous programmer and not I can make any changes to them.</p>