I'm trying to use order by without adding the order column in groupby, it only works if I execute it directly from the database but from laravel I get database error
I made this eloquent code
Comment::select('product_id')->where('shop_name', $shop)->groupby('product_id')->distinct()->orderBy('created_at')->paginate(12)
it will product the following query
select distinct DISTINCT(product_id) from
comments
whereshop_name
= 'shopname' group byproduct_id
order bycreated_at
asc limit 12 offset 0
if I rub the above query directly in database it works
but if I use Laravel eloquent code it fires this error
SQLSTATE[42000]: Syntax error or access violation: 1055 'areviews_areviewzappz.comments.created_at' isn't in GROUP BY (SQL: select distinct DISTINCT(product_id) from
comments
whereshop_name
= 'shopname' group byproduct_id
order bycreated_at
asc limit 12 offset 0)
how can I solve this issue ?