title: How do I make aliases on codeigniter when using the join library
body: <p>I have tried to make <strong>aliases</strong> into the query so that it does not give the error of not unique tables. </p>
  
  <p>as you can see i've placed <em>'AS'</em> with a new name after but it gives me an <strong>error</strong>. How am I doing this wrong?<br>
  this is what I have in my model:</p>
  
  <pre><code>&lt;?php 
  class Joins_model extends CI_Model{
      private $table = 'cm_proveedor, cm_compras, cm_valuacion, cm_valuacionr, cm_nomina, cm_empleado';
      function _construct(){
         parent::Model();
      }
  
      function get_reg($data){
  
          $this-&gt;db-&gt;select('
                              cm_valuacion.tipo_r AS valR,
                              cm_valuacion.mano_obra AS valM,
                              cm_valuacion.hojalateria AS valH,
                              cm_valuacion.pintura AS valP,
                              cm_valuacion.mecanica AS valMec,
                              cm_valuacion.refaccion AS valRef,
                              cm_valuacion.shojalateria AS valSH,
                              cm_valuacion.tipo AS valT,
                              cm_valuacion.spintura AS valSP,
                              cm_valuacion.costoHojalateria AS valCH,
                              cm_valuacion.smecanica AS valSM,
                              cm_valuacion.costoPintura AS valCP,
                              cm_valuacion.costoMecanica AS valCM,
                              cm_valuacion.pv_hojalateria AS valPH,
                              cm_valuacion.pv_pintura AS valPP,
                              cm_valuacion.pv_mecanica AS valPM,
                              cm_valuacion.pc_hojalateria AS valPH,
                              cm_valuacion.pc_pintura AS valPPin,
                              cm_valuacion.pc_mecanica AS valPMec,
                              cm_compras.precio,
                              cm_proveedor.nombre,
                              cm_nomina.nomina,
                              cm_empleado.nombre,
                              cm_nomina.id_nomina_gral
                              ',FALSE);
  
          $this-&gt;db-&gt;from('cm_valuacion');
          $this-&gt;db-&gt;join('cm_valuacionr','cm_valuacionr.id_siniestro = cm_valuacion.id_siniestro');
          $this-&gt;db-&gt;join('cm_compras','cm_valuacionr.id_siniestro = cm_compras.id_siniestro');
          $this-&gt;db-&gt;join('cm_proveedor','cm_proveedor.id = cm_compras.id_proveedor');
          $this-&gt;db-&gt;join('cm_nomina','cm_nomina.id_siniestro = cm_compras.id_siniestro');
          $this-&gt;db-&gt;join('cm_empleado','cm_nomina.id_empleado = cm_empleado.id');
          $this-&gt;db-&gt;join('cm_nomina_gral','cm_nomina.id_nomina_gral = cm_nomina_gral.id');
          $this-&gt;db-&gt;where('cm_valuacion.id_siniestro',$data);
          //$this-&gt;db-&gt;order_by('id','asc');
          $this-&gt;db-&gt;distinct();
          return $this-&gt;db-&gt;get($this-&gt;table);
      }
  
  
  }
  ?&gt;
  </code></pre>
  
  <p>the error that I get is:</p>
  
  <blockquote>
    <p>A Database Error Occurred
    Error Number: 1066
    Not unique table/alias: 'cm_valuacion'
    SELECT DISTINCT cm_valuacion.tipo_r AS valR, cm_valuacion.mano_obra AS valM, cm_valuacion.hojalateria AS valH, cm_valuacion.pintura AS valP, cm_valuacion.mecanica AS valMec, cm_valuacion.refaccion AS valRef, cm_valuacion.shojalateria AS valSH, cm_valuacion.tipo AS valT, cm_valuacion.spintura AS valSP, cm_valuacion.costoHojalateria AS valCH, cm_valuacion.smecanica AS valSM, cm_valuacion.costoPintura AS valCP, cm_valuacion.costoMecanica AS valCM, cm_valuacion.pv_hojalateria AS valPH, cm_valuacion.pv_pintura AS valPP, cm_valuacion.pv_mecanica AS valPM, cm_valuacion.pc_hojalateria AS valPH, cm_valuacion.pc_pintura AS valPPin, cm_valuacion.pc_mecanica AS valPMec, cm_compras.precio, cm_proveedor.nombre, cm_nomina.nomina, cm_empleado.nombre, cm_nomina.id_nomina_gral FROM (<code>cm_valuacion</code>, <code>cm_proveedor</code>, <code>cm_compras</code>, <code>cm_valuacion</code>, <code>cm_valuacionr</code>, <code>cm_nomina</code>, <code>cm_empleado</code>) JOIN <code>cm_valuacionr</code> ON <code>cm_valuacionr</code>.<code>id_siniestro</code> = <code>cm_valuacion</code>.<code>id_siniestro</code> JOIN <code>cm_compras</code> ON <code>cm_valuacionr</code>.<code>id_siniestro</code> = <code>cm_compras</code>.<code>id_siniestro</code> JOIN <code>cm_proveedor</code> ON <code>cm_proveedor</code>.<code>id</code> = <code>cm_compras</code>.<code>id_proveedor</code> JOIN <code>cm_nomina</code> ON <code>cm_nomina</code>.<code>id_siniestro</code> = <code>cm_compras</code>.<code>id_siniestro</code> JOIN <code>cm_empleado</code> ON <code>cm_nomina</code>.<code>id_empleado</code> = <code>cm_empleado</code>.<code>id</code> JOIN <code>cm_nomina_gral</code> ON <code>cm_nomina</code>.<code>id_nomina_gral</code> = <code>cm_nomina_gral</code>.<code>id</code> WHERE <code>cm_valuacion</code>.<code>id_siniestro</code> = '6489'
    Filename: C:\xampp\htdocs\index\system\database\DB_driver.php
    Line Number: 330</p>
  </blockquote>