title: CodeIgniter - Error Number: 1146 (Table doesn't exist after execute a "CREATE TABLE" command)
body: <p>I've posted yesterday an issue with an mySQL update syntax on CodeIgniter in here:
  <a href="https://stackoverflow.com/q/29981882/4853149">CodeIgniter - MySQL Error 1064 (Update table1 inner join table2(...))</a></p>
  
  <p>But now after I solved that problem, another one come up. Now the update query doesn't know the new created table. But if I change to a select statement, it works smoothly.</p>
  
  <p>For that reason I've decided to post the full script.</p>
  
  <p><strong>Code:</strong></p>
  
  <pre><code>&lt;?php
  
  
  
  $this-&gt;load-&gt;database();
  
  $query_tbaux='CREATE TABLE IF NOT EXISTS STUDY_LIST_AUX AS (
  
  SELECT DISTINCT p.pat_id, p.pat_custom1 age, p.pat_name, 
  p.pat_sex, s.study_iuid, p.pat_birthdate, s.accession_no, 
  s.study_datetime date_s, s.study_desc, s.mods_in_study, s.pk, 
  c.institution, s.study_block, s.study_urgent, 
  \'0000-00-00 00:00:00\' AS \'report_date\', \'{null}\' AS \'report_status\',
  s.study_tipo, 
  s.study_src, 
  s.study_consulta
  FROM study s
  INNER JOIN patient p ON s.patient_fk = p.pk
  INNER JOIN series c ON c.study_fk = s.pk
  INNER JOIN rel_users_hosp u ON u.hosp_id = c.institution
  WHERE s.study_datetime &gt;= \'2015-04-26 00:00:00\'
  AND s.study_datetime &lt;= \'2015-04-30 23:59:59\'
  AND s.study_iuid IS NOT NULL
  AND u.user_id =  \'admin\'
  
  )';
  
  if ($this-&gt;db-&gt;query($query_tbaux))
      {
          echo "Q True!&lt;br&gt;&lt;br&gt;";
          $data = array(
                 'STUDY_LIST_AUX.report_date' =&gt; "DATE_FORMAT(study_report.report_date,'%Y-%m-%d %h:%i:%s')",
                 'STUDY_LIST_AUX.report_status' =&gt; 'study_report.report_status',
              );
  
          $this-&gt;db-&gt;update('STUDY_LIST_AUX, study_report', $data, array('STUDY_LIST_AUX.study_iuid'=&gt;'study_report.study_iuid'));
      }
      else
          {
              echo "Q False&lt;br&gt;&lt;br&gt;";
          };
  
  
  ?&gt;
  </code></pre>
  
  <p><strong>Display/Error:</strong></p>
  
  <blockquote>
    <p>Q True!</p>
    
    <p><strong>A Database Error Occurred</strong></p>
    
    <p><em>Error Number: 1146</em></p>
    
    <p><em>Table 'pacsdb.STUDY_LIST_AUX,' doesn't exist</em></p>
    
    <p><em>UPDATE <code>STUDY_LIST_AUX,</code> <code>study_report</code> SET</em>
    <em><code>STUDY_LIST_AUX</code>.<code>report_date</code> =</em>
    <em>'DATE_FORMAT(study_report.report_date,\'%Y-%m-%d %h:%i:%s\')',</em>
    <em><code>STUDY_LIST_AUX</code>.<code>report_status</code> = 'study_report.report_status' WHERE</em>
    <em><code>STUDY_LIST_AUX</code>.<code>study_iuid</code> = 'study_report.study_iuid'</em></p>
  </blockquote>
  
  <p>I've checked phpmyadmin after refresh the page and the table really exists and it contains the data from the select statement.Can you please tell me what mistake I did?</p>