Can show your desired SQL? Can't understand what you meant by completed: group|type|user_id
Nov 10, 2020
9
Level 1
How to query by row's column value?
I've got a few tables constructed in this manner:completed: group|type|user_id and for every type I have a table user_id|group.
I need to count how many of the second type table entries are correspoding with first table rows. So, I am doing this:
$query->withCount(['completed' => function ($query) use ($user) {
$query->where('user_id', $user->id);
}]);
However, I have no idea how to insert a whereColumn to check for completed.group = currentTable.group. Could anybody guide me?
Thanks!
Level 27
DB::table('completed')
->join('currentTable', function ($join) use ($user) {
$join->on('currentTable.group', 'completed.group')
->on('currentTable.user_id', 'completed.user_id);
})->count();
Please or to participate in this conversation.