title: Laravel Eloquent - Select MAX with other columns
body: <p>I'm trying to select a number of columns along with MAX. The raw query would be something like: <code>SELECT users.id, ..., MAX(ur.rank) AS rank</code> but I cannot figure out how to do it using the query builder supplied by Laravel in Eloquent.</p>
  
  <p>This is my attempt:</p>
  
  <pre><code>$user = User::join('users_ranks AS ur', function($join) {
      $join -&gt;on('ur.uid', '=', 'users.id');
  })
  -&gt;where('users.id', '=', 7)
  -&gt;groupBy('users.id')
  -&gt;first(['users.id', 'users.username', 'MAX(ur.rank) AS rank']);
  </code></pre>
  
  <p>I simply cannot figure it out. What I want to achieve is I'm selecting a user where users.id = 7, and I'm wanting to select the MAX rank that's in users_ranks where their users_ranks.uid = users.id.</p>
  
  <p>I was told to avoid sub-queries as when working with large result sets, it can slow things down dramatically.</p>
  
  <p>Can anyone point me in the right direction? Thanks.</p>