title: Codeigniter simple SQL query
body: <p>My query work fine on Phpmyadmin but i try to convert this one to codeigniter query type and i dont know how with nested query. So, i want to inject this query with normal SQL format:</p>
  
  <pre><code>select * from conversations c join messages m on m.mconv_num = c.cnum where c.cuser2 = 2 and not exists (select * from messages m2 where m2.mconv_num = m.mconv_num and m2.mtime &gt; m.mtime);
  </code></pre>
  
  <p>I try with this query:</p>
  
  <pre><code>$query = 'SELECT * FROM conversations c JOIN messages m ON m.mconv_num = c.cnum WHERE c.cuser2 = 2 AND NOT EXISTS (SELECT * FROM messages m2 WHERE m2.mconv_num = m.mconv_num AND m2.mtime &gt; m.mtime)';
  $this-&gt;db-&gt;query($query);
  </code></pre>
  
  <p>But i have this error:</p>
  
  <blockquote>
    <p>A Database Error Occurred</p>
  </blockquote>
  
  <pre><code>No tables used 
  SELECT *
  </code></pre>
  
  <p>Screenshot of the error: <a href="https://image.noelshack.com/fichiers/2018/03/5/1516363991-sans-titre.png" rel="nofollow noreferrer">https://image.noelshack.com/fichiers/2018/03/5/1516363991-sans-titre.png</a></p>
  
  <p>So, if someone can help me to execut my query or convert this one to codeigniter format. Thanks you !</p>
  
  <p><strong>MODEL:</strong></p>
  
  <pre><code>  public function get_conversations_last_message_by_id($userLoginID)
      {
          $query = 'SELECT * FROM conversations c JOIN messages m ON m.mconv_num = c.cnum WHERE c.cuser2 = $userLoginID AND NOT EXISTS (SELECT * FROM messages m2 WHERE m2.mconv_num = m.mconv_num AND m2.mtime &gt; m.mtime)';
          $this-&gt;db-&gt;query($query);
  
          $query = $this-&gt;db-&gt;get();
          if ($query-&gt;num_rows() &gt; 0) {
              return $query-&gt;result();
          } else {
              return false;
          }
      }
  </code></pre>