1 month ago

Syntax Error on group by

Posted 1 month ago by MattB

Trying to group by category but only on categories with at least one entry, using the below code:

 $categoryIds = array();
            foreach($gameCount as $game)
                if($game->total > 0 )
                    array_push($categoryIds, $game->category_id );
            $categories = Category::wherein('id', $categoryIds)

When I run it, I get this error:

SQLSTATE[42000]: Syntax error or access violation: 1055 '' isn't in GROUP BY (SQL: select * from `categories` where `id` in (1, 2, 8, 17, 21, 26, 35) group by `company_id`)

Any ideas? I can turn 'strict' => true, to 'strict' => false which will fix it but I don't wish to do this as it breaks other parts of the database searches.

Please sign in or create an account to participate in this conversation.