I have a SQL SELECT query that works in mySQL, both from PHPmyadmin and from the console. However, when it was converted to Laravel query builder, it borked with the following error message:
SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #3 of SELECT list is not
in GROUP BY clause and contains nonaggregated column 'wcce_dev.client_contacts.family_name'
which is not functionally dependent on columns in GROUP BY clause; this is incompatible with
sql_mode=only_full_group_by
The following is the SQL SELECT query:
SELECT `clients`.name, `clients`.address_1, `client_contacts`.family_name,
`client_contacts`.given_name, `client_contacts`.office_country,
`client_contacts`.office_city, `client_contacts`.office_number, `client_contacts`.position, `contact_titles`.description
FROM `clients`
INNER JOIN `client_contacts`
ON `clients`.entry = `client_contacts`.client
INNER JOIN `contact_titles`
ON `client_contacts`.title = `contact_titles`.code
GROUP BY `clients`.entry
ORDER BY `clients`.entry ASC;
The following is the Laravel query builder statement:
DB::table('clients')
->select('clients.name', 'clients.address_1', 'client_contacts.family_name',
'client_contacts.given_name', 'client_contacts.office_country',
'client_contacts.office_city', 'client_contacts.office_number',
'client_contacts.position', 'contact_titles.description')
->join('client_contacts','clients.entry','=','client_contacts.client')
->join('contact_titles','client_contacts.title','=','contact_titles.code')
->groupBy('clients.entry')
->orderBy('clients.entry','asc')
->get();
It's very strange. Any help is greatly appreciated.
clients.entryfield to your select query. and trySET GLOBAL sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY',''));or direct change it from MySql settings.