$old_records = DB::connection("mysql_old_s")->table('leads')
->select(DB::raw('count(*) as source_count, source'))
->groupBy('source')
->get();
dd($old_records); // works right
This query works right. I want to add one more column like id or created_at to select
I couldn't do it as following:
$old_records = DB::connection("mysql_old_s")->table('leads')
->select('id',DB::raw('count(*) as source_count, source'))
->groupBy('source')
->get();
dd($old_records); // it gives an error
It gives me an error that is:
SQLSTATE[42000]: Syntax error or access violation: 1055 Expression #1 of SELECT list is not in GROUP
BY clause and contains nonaggregated column 'crmclini_crmv2.leads.id' which is not functionally
dependent on columns in GROUP BY
clause; this is incompatible with sql_mode=only_full_group_by (SQL: select `id`, count(*) as
source_count, source , id from `leads` group by `source`)