Skip to content
Advertisement

Get most recent row with group by and Laravel

Even though there are multiple questions like this I can’t get my query to return the row with the most recent date with a group by.

I have the following table..

and I’m tryin to get the rows with most recent date.

Currently this query returns the rows with the last recent date.

Advertisement

Answer

The problem is that the result set will be first grouped then ordered. You can use nested select to get what you want.

SQL Query:

With Laravel:

You just need to add your where() clauses.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement