title: codeigniter complex join only if rows don't exist
body: <p>I'm making a dating application, much like tindler. Users can like or dislike other users, and if two users both like each other they get the option to chat with eachother. Currently building the query to pull a random profile and one of their pictures at random:</p>
  
  <pre><code>$data = $this-&gt;db
  -&gt;select('users.id,display_name,city,state,gender,users_pictures.picture')
    -&gt;join('users_pictures','users_pictures.user_id = users.id')
    -&gt;order_by('id','RANDOM')
    -&gt;limit(1)
    -&gt;where(array('users.approved'=&gt;1,'users_pictures.approved'=&gt;1))
    -&gt;where(array('users.id !='=&gt;$user_id))-&gt;get('users')-&gt;result_array();    
  </code></pre>
  
  <p>Now here's where I'm confused.. I have a table for likes_dislikes that consists of user_id, foreign_user_id, and event_type (like, dislike).</p>
  
  <p>If you disliked or liked a user already, I do not want them in my results. The only means I can think of handling this is to perform a second query which checks this, and then does another 'random' query if you have already liked/disliked them so that you only see users you haven't already rated. Is there a better way?</p>
  
  <p>Any help is much appreciated :)</p>