title: How write this complex query in codeigniter?
body: <p>I use mysql and try to write this query into a model of Codeigniter. This query run perfectly in phpmyAdmin.</p>
  
  <pre><code>SELECT 
          a.ar, 
          a.jabatan, 
          COUNT(*) AS JumlahWPBaru, 
          SUM( 
              CASE WHEN a.no_shim IS NOT NULL 
              THEN 1 
              WHEN a.no_shim IS NULL 
              THEN 0 
              END ) AS JumlahHimbauan
          FROM (
  
          SELECT 
              a.ar, 
              c.jabatan, 
              a.npwp, 
              a.kpp, 
              a.cab, 
              a.namawp, 
              b.kd_shim, 
              b.no_shim, 
              b.tgl_shim
          FROM mfwpbudi a
          LEFT JOIN tb_shimbauan b ON ( a.npwp = b.npwp ) 
          LEFT JOIN easystp_user c ON ( SUBSTR( a.ar, 1, 9 ) = c.id_user ) 
          WHERE a.tanggal_daftar &gt;  '2013-12-31'
          AND c.jabatan =  '05E'
          ) AS a
          GROUP BY a.ar
  </code></pre>
  
  <p>Here the model that I write.</p>
  
  <pre><code>function m_data_penyampaian_shim()
  {
      $this-&gt;db-&gt;query("SELECT 
          a.ar, 
          a.jabatan, 
          COUNT(*) AS JumlahWPBaru, 
          SUM( 
              CASE WHEN a.no_shim IS NOT NULL 
              THEN 1 
              WHEN a.no_shim IS NULL 
              THEN 0 
              END ) AS JumlahHimbauan
          FROM (
  
          SELECT 
              a.ar, 
              c.jabatan, 
              a.npwp, 
              a.kpp, 
              a.cab, 
              a.namawp, 
              b.kd_shim, 
              b.no_shim, 
              b.tgl_shim
          FROM mfwpbudi a
          LEFT JOIN tb_shimbauan b ON ( a.npwp = b.npwp ) 
          LEFT JOIN easystp_user c ON ( SUBSTR( a.ar, 1, 9 ) = c.id_user ) 
          WHERE a.tanggal_daftar &gt;  '2013-12-31'
          AND c.jabatan =  '05E'
          ) AS a
          GROUP BY a.ar");
      $qry=$this-&gt;db-&gt;get();
      return $qry-&gt;result();
  }
  </code></pre>
  
  <p>but I get the error : </p>
  
  <blockquote>
    <p>Error Number: 1096</p>
    
    <p>No tables used</p>
    
    <p>SELECT *</p>
    
    <p>Filename: C:\xampp\htdocs\himbauanwpbaru\system\database\DB_driver.php</p>
    
    <p>Line Number: 330</p>
  </blockquote>
  
  <p>How I solve this problem ? Are there something I left from the code above?
  I appreciate any suggestion and solutions.
  Thank you</p>