I am trying to return all users from my Laravel 5.5 database and group them by the month they registered like this..
$users = DB::table('users')
->orderBy('created_at')
->groupBy(DB::raw("MONTH(created_at)"))
->get();
But this is giving me an error
Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column
Where am I going wrong?
** Update **
The exact error mesage I am getting is...
SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'myapp.users.name' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by (SQL: select `name`, `email`, MONTH(created_at) month from `users` group by `month` order by `created_at` asc)