Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

Ligonsker's avatar

How to count results per the selection inside each of the "OR" clauses?

Hello,

If I have the following example table:

id | username | col_A | col_B | col_C 

and the following example query:

Table::select(...)
            ->where(function($query) {
                $query->where('col_A', 'some_value')
                              ->where('col_B', 'some_value');
                              ->where('col_C', 'some_value');
            })
            ->orWhere(function($query) {
                $query->where('col_A', 'some_other_value')
                              ->where('col_B', 'some_other_value');
            })
            ->orWhere(function($query) {
                $query->where('col_A', 'and_another_value');
            });

Is it possible to count how many rows are resulted from each of the orWhere blocks?

Ty

0 likes
4 replies
Ligonsker's avatar

@Sinnbeck Thanks. If I don't actually need the data of the columns but only the count, is it possible to do groupBy only instead?

Ligonsker's avatar

@Sinnbeck thank you, I posted a new question with more information instead of this one which is just vague with fake data. I'll delete it soon

Please or to participate in this conversation.