Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

HUNHammer98's avatar

database query select by distinct values

Hello,

I would like further develop this query by, selecting only distinct/groupby?? "h_name" and only getting the max calc_mem, whereDate('created_at', '>', $timeperiod), and having('calc_mem', '>', 0.9).

$lrgtimes = HDatas::select(DB::raw('calc_mem, h_name, alloc_lim, mem_peak, created_at'))
                                ->whereDate('created_at', '>', $timeperiod)
                                ->having('calc_mem', '>', 0.9)
                                ->get();

how is it possible?

0 likes
1 reply
sr57's avatar
$lrgtimes = \DB::select("SELECT h_name,MAX(calc_mem) FROM HDatas WHERE created_at > $timeperiod GROUP BY h_name HAVING MAX(calc_mem)>0.9");

Please or to participate in this conversation.