Crazylife
2 years ago
7594
22
Eloquent

How can i get the latest record in database based on datetime?

Posted 2 years ago by Crazylife

I have a table with value as shown below

id  branch_id       qty datetime
--- ---------       ----    -----------
1   1           2   2017-07-29 12:26:07
2   1           2   2017-07-29 12:26:07
3   2           3   2017-07-29 12:26:07
4   2           4   2017-07-28 12:26:07
5   2           1   2017-07-28 12:26:07
6   1           2   2017-07-28 12:26:07

And i want to display the latest datetime

id  branch_id       qty datetime
--- ---------       ----    -----------
1   1           2   2017-07-29 12:26:07
2   1           2   2017-07-29 12:26:07

How can i make it? I will select the latest record according to branch in where clause.

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