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?
When you use aggregate functions like
MIN(),MAX(),COUNT() AVG()you have to useGroup BYBut in latest
MYSQLu have to use all the columns in select as a group By too.In your
config/database.phpturn off the strict mode.'strict' => falseafter that you can use group by on a single column too.