title: how to get records from one column that is not in another column codeigniter
body: <p>hi i am using codeigniter , and i have a table like this </p>
  
  <p><img src="https://i.stack.imgur.com/4tQoo.png" alt="enter image description here"></p>
  
  <p>i want to get all records where <code>PreferenceID</code> value is not in <code>PreferenceParentID</code> column</p>
  
  <p>in this case i am  fitering table  also with the <code>EntityID</code> .  and <code>PreferenceParentID</code> shoul be <code>!= 0</code></p>
  
  <p>suppose i filter by <code>entityID</code> <code>53</code> </p>
  
  <p>my results shoul be </p>
  
  <pre><code>Couture , Denims
  </code></pre>
  
  <p>because <code>PreferenceID</code> is not in <code>PreferenceParentID</code> in both cases . i tried with <code>where_not_in()</code> but could not do . please help </p>
  
  <p>this is my query </p>
  
  <pre><code>    $table = $this-&gt;mastables['shop_profile_preferences'];
      $this-&gt;db-&gt;select('a.ProfilePreferenceID');
      $this-&gt;db-&gt;from($table." as a");
  
      $where2 = "(SELECT a.PreferenceParentID FROM ".$table.")";
      $this-&gt;db-&gt;where_not_in('a.PreferenceID', $where2);
  
      $this-&gt;db-&gt;where("a.EntityID",$shop_id);
      $this-&gt;db-&gt;where('a.PreferenceParentID !=',0);
  
      $query=$this-&gt;db-&gt;get();
  
      if($query-&gt;num_rows()&gt;0)
      {
          return $query-&gt;result_array();
      }
      else
      {
          return FALSE;
      }
  </code></pre>
  
  <p>the result of my query is </p>
  
  <pre><code>Array
  (
      [0] =&gt; Array
          (
              [ProfilePreferenceID] =&gt; 274
          )
  
      [1] =&gt; Array
          (
              [ProfilePreferenceID] =&gt; 275
          )
  
      [2] =&gt; Array
          (
              [ProfilePreferenceID] =&gt; 276
          )
  
  )
  </code></pre>
  
  <p>how to use <code>where_not_in()</code> properly . or ids there any other methods . please help  .....
  thanks in advance .</p>
  
  <p><strong>UPDATE</strong></p>
  
  <pre><code>    $table = $this-&gt;mastables['shop_profile_preferences'];
      $this-&gt;db-&gt;select('a.ProfilePreferenceID,a.ProfilePreferenceValue');
      $this-&gt;db-&gt;from($table." as a");
  
      $this-&gt;db-&gt;where('a.PreferenceParentID !=',0);
      $this-&gt;db-&gt;where('a.PreferenceID NOT IN (SELECT a.PreferenceParentID FROM '.$table.')', NULL, FALSE);
      $this-&gt;db-&gt;where("a.EntityID",$shop_id);
  
      $query=$this-&gt;db-&gt;get();
  
      if($query-&gt;num_rows()&gt;0)
      {
          return $query-&gt;result_array();
      }
      else
      {
          return FALSE;
      }
  </code></pre>