Skip to content
Advertisement

Select most recent row from MySQL for set of distinct keys

I have a table foo that looks like this:

For each set of distinct (user, a, b), I’d like to select the most recent timestamp and the value c

I’ve tried a few variations of the following without any luck

Advertisement

Answer

How about

UPDATE

you can use this subquery to get what you need. f2 will be the foo row that matches the distinct user,a,b and has the latest ts. This is equivalent to the CROSS APPLY statement in MSSQL.

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