title: How to resolve "isn't in GROUP BY" error in mysql query
body: <p>I have two models: <code>posts</code> and <code>likings</code> which have one-to-many relationship (so, one post has many likes). Likings model has also an <code>isActive</code> field which shows liking is active or passive.</p>
  
  <p>I want to get (sort) top 5 posts which had received maximum "active" likes (only likes whose isActive field is true would be considered).</p>
  
  <p>This is the query:</p>
  
  <pre><code>select posts.*, count(likings.id) as likes_count from 'posts'
  left join 'likings' on 'likings'.'post_id' = 'posts'.'id' and 'likings'.'isActive' = 1
  group by 'posts'.'id'
  order by 'likes_count' desc 
  limit 5
  </code></pre>
  
  <p>which is resulted from this laravel query:</p>
  
  <pre><code>Post::selectRaw('posts.*, count(likes.id) as likes_count')
      -&gt;leftJoin('likes', function ($join) {
          $join-&gt;on('likes.post_id', '=', 'posts.id')
               -&gt;where('likes.is_active', '=', 1);
      })
      -&gt;groupBy('posts.id')
      -&gt;orderBy('likes_count', 'desc')
      -&gt;take(5)
      -&gt;get();
  </code></pre>
  
  <p>And this is the error:</p>
  
  <pre><code>SQLSTATE[42000]: Syntax error or access violation: 1055
  'database.posts.user_id' isn't in GROUP BY
  </code></pre>
  
  <p>Here, <code>posts.user_id</code> is also a field of <code>posts</code> table and shows the owner of the post.</p>
  
  <p>How can I resolve this error? It seems it isn't logical to change mysql config (probably deleting <code>ONLY_FULL_GROUP_BY</code> mode), but minimum change in the query.</p>