title: How to do a self join in laravel resulting in distinct values
body: <pre><code>ID|user_id   |book_id   |author
  1 |8         |7         |bill
  2 |8         |6         |sally
  3 |3         |7         |rob
  4 |3         |4         |sarah
  5 |3         |6         |jane
  6 |8         |7         |frank
  </code></pre>
  
  <p>What I want to achieve are rows that user_id 8 book_ids match that of user_id 3 book_id. but only user_8s rows selected. And also distinct by book_id. So i want the result to be:  </p>
  
  <p>row 1,
  row 2</p>
  
  <p>So far I have this but unfortunately I keep getting row 6 as well as row 2 and row 1.  Basically i want the result to be distinct by book_id but im unsure how to do this.</p>
  
  <pre><code>$check = DB::table('table as u1') 
  -&gt;join('table as u2','u1.book_id', '=', 'u2.book_id')
  -&gt;where('u2.user_id', 8)-&gt;where('u1.user_id', 3)
              -&gt;get();
  </code></pre>