EckyEckyPtang's avatar

SQLITE requires group by when using 'having'

The following query works fine with Mysql:

Community::withCount('stories')->having('stories_count', '>', 20)->whereNotExists(function($query) {
            $query->select(DB::raw(1))
                ->from('communities_followers')
                ->whereRaw('communities_followers.community_id = communities.id and communities_followers.user_id = '. auth()->id());
        })->inRandomOrder()->first();

But my testsuite uses sqlite with an in memory database and fails because the query does not have a group by field. Is there anyway to disable that requirement in SQLITE? If not, what would be the proper group in this statement?

0 likes
4 replies
bugsysha's avatar

SQLITE requires group by when using 'having'

Not only SQLite, MySQL does also.

sr57's avatar

Not sure, Try PRAGMA strict=Off;

... and let's know.

Please or to participate in this conversation.