Monday, April 10, 2017

Count repeated values in different tables in Laravel

I am trying to sum the equal values of different columns using the Laravel query constructor.

I try this method to test and count the number of numbers repeated in this table:

$draw_count = DB::table('draws')
                ->selectRaw('ball1,COUNT(*) as count')
                ->groupBy('ball1')
                ->orderBy('count', 'desc')
                ->get();

This method returns well the count of the numbers recorded in column ball1:

enter image description here

But I need to do the same in the other columns ball2, ball3, ball4, ball5 and ball6, count the repeated numbers and show it as a single value.



via Edward Palen

Advertisement