title: Codeigniter: No Tables Used
body: <p>I've a table of users. Which data is lot of duplicate data. I want to keep all those duplicate data. So I've 3 conditions</p>
  
  <ol>
  <li>Account with no picture</li>
  <li>Account with picture</li>
  <li>Duplicate account with picture or no picture</li>
  </ol>
  
  <p>For example</p>
  
  <p>ID | Email | Picture<br>
  1  | ba@mail.com | img.jpg<br>
  2  | ba@mail.com | <i>NULL</i><br>
  3  | ba@mail.com | img2.jpg<br>
  4  | ba@mail.com | <i>NULL</i><br>
  5  | aa@mail.com | <i>NULL</i></p>
  
  <p>So how to get the ID of those duplicate account, but prioritizing picture is not null, and prioritizing the latest ID? (I want it returns '3')</p>
  
  <p>Here I Try the code</p>
  
  <pre><code>$this-&gt;db-&gt;select('id');
          $this-&gt;db-&gt;from('users');
          $this-&gt;db-&gt;where('email', $email);
          $query0 = $this-&gt;db-&gt;get();
  
          if($query0-&gt;num_rows() == 1){
              return $query0-&gt;row('id');
          } else {
              $this-&gt;db-&gt;select('id');
              $this-&gt;db-&gt;from('users');
              $this-&gt;db-&gt;where(array('email' =&gt; $email, 'picture IS NOT' =&gt; NULL));
              $query1 = $this-&gt;db-&gt;get();
              if($query1-&gt;num_rows() == 1){
                  return $query1-&gt;row('id');
              } else {
                  $this-&gt;db-&gt;select('id');
                  $this-&gt;db-&gt;from('users');
                  $this-&gt;db-&gt;where('email', $email);
                  $this-&gt;db-&gt;limit('1');
  
                  return $this-&gt;db-&gt;get()-&gt;row('id');
              }
  </code></pre>
  
  <p>It works well if account duplicate, and both of them with NULL on picture column. But it doesn't work well when the account doesn't duplicate OR duplicate but one of them have a picture not null.</p>
  
  <p>Here the error code:
  Error Number: 1096
  No tables used</p>
  
  <p>Thank you!</p>