title: Codeigniter Insert with Select Query
body: <p>Is there a way to make this Query work in MySQL Codeigniter </p>
  
  <p>Basically is make a select inside a Insert to avoid double Query </p>
  
  <p>I want to make an INSERT a row in a table called <strong>recibos_nomina</strong> but the field <strong>recibos_nomina.id_usuario</strong> is one a table called <strong>usuarios</strong>  i have <strong>usuarios.rfc</strong> and i want to nest <strong>SELECT id FROM usuarios WHERE rfc = XXX</strong> to get the id and insert  in <strong>recibos_nomina.id_usuario</strong> with one Query only, this is possible with MySQL but i don't know how to make it with codeigniter.</p>
  
  <hr>
  
  <pre><code>$this-&gt;db-&gt;trans_begin();
  $this-&gt;db-&gt;query('insert into recibos_nomina(id_empresa, id_usuario, fecha, folio, total, uuid, url_xml, temporal, folio_fiscal, fechahora_certificado, csd_sat, sello_cfd, sello_sat, sello)
      values(?, (SELECT id FROM usuarios WHERE rfc = ?), ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)', array(
                              2,
                              //intval($this-&gt;post('id_empleado')),
                              $recibo-&gt;usuario-&gt;rfc,
                              date("Y-m-d"),
                              $recibo-&gt;folio,
                              $recibo-&gt;total,
                              $recibo-&gt;uuid,
                              $recibo-&gt;url_xml,
                              1,
                              $recibo-&gt;uuid,
                              //str_replace("T", " ", $recibo-&gt;fecha),
                              $recibo-&gt;fecha,
                              $recibo-&gt;csd_sat,
                              $recibo-&gt;sello_cfd,
                              $recibo-&gt;sello_sat,
                              $recibo-&gt;sello_cfd
                          ));
                          $id_recibo = $this-&gt;db-&gt;insert_id();
  </code></pre>