skyline
1727
6
Eloquent

How to get last record of a group?

Posted 2 years ago by skyline

Hi there, I came across with a problem and stuck on it , I want to get the last record in a group of value. For example :

I have a table called 'flight_times' , the table has those columns respectively : id, aircraft_id , departure, arrival ,flight_time, effective_from. I want to group that table by departure and arrival , then want to get the records that has the latest effective_from value. When I try to use groupBy statement , it always gives the first record . That is a big problem for me. Any helps ?

Thanks.

Please sign in or create an account to participate in this conversation.