I'm working on a laravel project and I'am trying to use where with groupBy on my query. The below is example of drug_transactions table.
screen_id patient_id drug_id
1 1 1
1 1 2
1 1 3
2 1 1
3 2 1
I would like to get screen_id for patient_id = 1. Then I use eloquent as below.
$drugtransactiongroups = DrugTransaction::where('patient_id',1)
->groupBy('screen_id')
->get();
My need result should return screen_id= 1 and 2. But I have an error as below instead.
SQLSTATE[42000]: Syntax error or access violation: 1055 'zigmaclinic.drug_transactions.id' isn't in GROUP BY (SQL: select * from
drug_transactionswherepatient_id= 1 group byscreen_id)
Any advice or guidance on this would be greatly appreciated, Thanks.