title: Laravel 4 - Get value from another table's field and join to query
body: <p>I am having a lot of trouble trying to work this query. I'm fairly new to Laravel 4 so go easy.</p>
  
  <p>What I have is 2 tables. Uploads and Albums. Currently, I am trying to output all albums based on user's ID, and grabbing the latest thumbnail of an upload associated with that album.</p>
  
  <p>This is the code I am using currently:</p>
  
  <pre><code>DB::table("albums")
  -&gt;select("albums.*","uploads.thumbnail")
  -&gt;join("uploads", "uploads.albumid", "=", "albums.id")
  -&gt;where("albums.userid", "=", Auth::user()-&gt;id)
  -&gt;orderBy("uploads.id", "ASC")
  -&gt;get()
  </code></pre>
  
  <p>The output is wrong. What the output shows is pretty much the opposite. It's looping through the uploads, rather than albums and retrieving the first record of the albums table.</p>
  
  <pre><code>(
  [0] =&gt; stdClass Object
      (
          [id] =&gt; 1
          [userid] =&gt; 1
          [private_code] =&gt; PJ3r6Ps3c5rRrceKRLvWmpk4o5GvHKHk7QCUnRkTmlwUnxnjmL9kVaOa1N4Tm124
          [slug] =&gt; album-test-1
          [name] =&gt; Album test 1
          [description] =&gt; Album test 1
          [privacy] =&gt; Public
          [created_at] =&gt; 
          [updated_at] =&gt; 
          [thumbnail] =&gt; 6s/zj/4e/6SZj4Ev409fU2b3NYHzgW7O9Jn3MFeDb_thumbnail.jpg
      )
  
  [1] =&gt; stdClass Object
      (
          [id] =&gt; 1
          [userid] =&gt; 1
          [private_code] =&gt; PJ3r6Ps3c5rRrceKRLvWmpk4o5GvHKHk7QCUnRkTmlwUnxnjmL9kVaOa1N4Tm124
          [slug] =&gt; album-test-1
          [name] =&gt; Album test 1
          [description] =&gt; Album test 1
          [privacy] =&gt; Public
          [created_at] =&gt; 
          [updated_at] =&gt; 
          [thumbnail] =&gt; 17/zs/11/17zs11CwBKsPilpeMVjH7A7gTEcRxb4P_thumbnail.jpg
      )
  )
  </code></pre>
  
  <p>I want to loop through albums, whilst retrieving that album's recent upload thumbnail to use as the thumbnail for the album.</p>