Skip to content
Advertisement

LIMIT 1 by Column On Query Returning Multiple Results?

I have a user_certifications table, with these props:

So, a user can be listed multiple times with a variety of certs. I have a list of user_ids for which I need to get ONLY the most recently updated record. So for one user it would be:

How do I do this efficiently if I need ONLY the last dated entry for each of a number of users. E.g. similar query, but WHERE user_id IN (x,y,z) and returning one entry per user, with the latest date?

P.S. – I apologize for the title, I don’t know how to word this.

Advertisement

Answer

Use distinct on:

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