Skip to content

[Bug] Query Builder count() return wrong number with groupBy() #4306

Closed
@wafgomes

Description

@wafgomes

Using Query Builder count() with groupBy() doesn't return the correct number of rows, not considering the group by condition

I just made an example to show the problem

consider following table and code:

id cat desc
1 1 abc
2 1 abc
3 2 abc
$count = DB::table('product')
    ->where('cat', 1)
    ->groupBy('cat')
    ->count();

var_dump($count);

$count = DB::table('product')
    ->where('cat', 1)
    ->groupBy('cat')
    ->get();

var_dump(count($count));

Output:

int(2)

int(1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions