title: How to insert records using select in codeigniter active record
body: <p>I want to implement a sql query using CodeIgniter Active Record class. The query looks like this..</p>
  
  <pre><code>INSERT california_authors (au_id, au_lname, au_fname)
  SELECT au_id, au_lname, au_fname
  FROM authors
  WHERE State = 'CA'
  </code></pre>
  
  <p>Is this possible in CodeIgniter without using the $this->db->query method?</p>
  
  <p><strong>Solution</strong>:</p>
  
  <pre><code>$this-&gt;db-&gt;select('au_id, au_lname, au_fname');
  $this-&gt;db-&gt;from('california_authors');
  $this-&gt;db-&gt;where('state', 'CA');
  $query = $this-&gt;db-&gt;get();
  
  if($query-&gt;num_rows()) {
      $new_author = $query-&gt;result_array();
  
      foreach ($new_author as $row =&gt; $author) {
          $this-&gt;db-&gt;insert("authors", $author);
      }           
  }
  </code></pre>
  
  <p>Regards</p>