I have 3 fields in an employees table: personal_id, personal_id_type, and date_registered.
I need to find all the rows, one row for each personal_id + personal_id_type (here is where I think I can use a GROUP), but since there may be many entries for the same personal_id + personal_id_type (because employees can quit and get hired again later), I need to fetch only the newest entry (order by date_registered DESC).
Is this conceptually correct? What would be the syntax for grouping by 2 fields? Will I achieve what I need with that?
Edit: I’m sorry, actually there are a lot of fields, so I need the newest row, not only the newest date.
Find the newest date for every
(personal_id, personal_id_type)combination in a subquery, then join to the original table: