SkyCoder
3 months ago

Leftjoin with groupby skips groupby

Posted 3 months ago by SkyCoder

I have Users that I want to count by left joining table for workouts and getting one row for each user.

$users->leftJoin('workout', function($join){
                        $join->on('user.id', '=', 'workout.user_id')->where('workout.user_id', '>', 1)->groupBy('user.id')->orderBy('workout.id');
                })

First I dont get only one per workout, but for every workout. Like: w1 uid - 1 w2 uid - 2 w3 uid - 1

I get 3 users instead of 2...

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