Level 73
Not knowing your column names nor the model, so give this a try and let me know:
// replace name and count with your column names
Model::select('name', \DB::raw('max(count)'))->groupBy('name')->get();
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
I have the following data
item 1 - 5
item 2 - 7
item 3 - 4
item 1 - 4
item 2 - 20
what query do i need to do to display this kind of result
item 1 - 5
item 2 - 20
item 3 - 4
names should be distinct and get the highest value.
Not knowing your column names nor the model, so give this a try and let me know:
// replace name and count with your column names
Model::select('name', \DB::raw('max(count)'))->groupBy('name')->get();
Please or to participate in this conversation.