Getting a sql error in my query, i believe maybe is malformed my query builder but cant figure out what im doing wrong.
Alredy tried testing my query directlly in the DB and it works, but when translating with query builder it doesnt work.
$totalUserForCountry = DB::table('countries')
->select('countries.name', DB::raw('COUNT(users.country_id) as total'))
->join('users', 'users.country_id', '=', 'countries.id')
->groupBy('users.country_id')
->get();
My error code is:
SQLSTATE[42000]: Syntax error or access violation: 1055 'db.countries.name' isn't in GROUP BY (SQL: select
countries.name, COUNT(users.country_id) as total fromcountries
inner joinusersonusers.country_id=countries.idgroup byusers.country_id)
Mysql query directlly to DB:
SELECT ct.name AS CountryName, COUNT(us.country_id) AS NumberOfUsers FROM countries AS ct
INNER JOIN users AS us
ON
us.country_id = ct.id
GROUP BY us.country_id;
P.S. It only works if i disable 'strict' mode to false
SELECT countries.name, COUNT(users.country_id) as total FROM countries INNER JOIN ... users ON ,,, GROUP BY users.country_idwhich is invalid ANSI/iSO SQL 92 - Raymond NijlandAlredy [sic] tried testing my query directlly [sic] in the DB and it works- Prove it. - Strawberry->groupBy('users.country_id', 'countries.name')- Frankich