1

I have this code in laravel

    $blogs = BlogCategoryGroup::with([
      'blogPost' => function($query) {
        $query
          ->with([
            'groups' => function($query) {
              $query->with('blogTag')->get();
            }])
          ->get();
      },
      'blogCategory'
    ])
    ->groupBy('blog_category_groups.blog_post_id')
    ->whereCategoryId($request->input('parent_category'))
    ->orWhere('category_id', $request->input('first_sub_category'))
    ->orWhere('category_id', $request->input('second_sub_category'))
    ->get();

which has equivalent query

select * from `blog_category_groups` where `category_id` = 2 or `category_id` = 3 or `category_id` = 4 group by `blog_category_groups`.`blog_post_id`

the difference when I run the laravel code, I got this error

SQLSTATE[42000]: Syntax error or access violation: 1055 'database.blog_category_groups.id' isn't in GROUP BY (SQL: select * from `blog_category_groups` where `category_id` = 2 or `category_id` = 3 or `category_id` = 4 group by `blog_category_groups`.`blog_post_id`)

but running the query on heidiSQL I got a single result

why this has to be an error to my laravel code?

Fil
  • 8,225
  • 14
  • 59
  • 85
  • 1
    Possible duplicate of [Syntax error or access violation: 1055 Expression #17 in group by](https://stackoverflow.com/questions/40299773/syntax-error-or-access-violation-1055-expression-17-in-group-by) – Devon Bessemer Jun 12 '18 at 14:51
  • Above is a Laravel question, the bigger topic is https://stackoverflow.com/questions/34115174/error-related-to-only-full-group-by-when-executing-a-query-in-mysql which shows more about that error. – Devon Bessemer Jun 12 '18 at 14:53

0 Answers0