dimanche 15 avril 2018

Syntax error or access violation: 1140 Mixing of GROUP columns laravel

I have written this query with pagination in it

$items = Item::select('items.*', 'sub_category_name', 'category_name', 'sub_category_slug', 'category_slug')
        ->join('sub_categories AS sc', 'sc.sc_id', 'items.sub_category_id')
        ->join('categories AS c', 'c.category_id', 'sc.category_id')
        ->where('items.is_active', '=', 1)
        ->where('sc.is_active', '=', 1)
        ->where('c.is_active', '=', 1)
        ->where('sc.sc_id', '=', $sub_category_id)
        ->paginate(1);

But it says

Syntax error or access violation: 1140 Mixing of GROUP columns (MIN(),MAX(),COUNT(),...) with no GROUP columns is illegal if there is no GROUP BY clause

But when I add ->groupBy('item_id'); it says

Syntax error or access violation: 1055 'books.items.item_name' isn't in GROUP BY

But when I do item_name in groupBy clause it says to groupBy the next column. Why?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire