I have a table of rules with effective dates, which apply to specific employee types. I want to find the most recently effective rule per employee type.
One technique that was suggested was to perform a self-join, in order to first perform the grouping and selection, and then to perform the proper query having found the selected rules.
The SQL I have is as follows:
SELECT dtr.employee_type
,dtr.start_time
,dtr.end_time
FROM (
SELECT MAX(effective_date) AS maxdate
,employee_type
FROM default_time_rules
GROUP BY employee_type
) AS grouped_dtr
INNER JOIN default_time_rules AS dtr ON dtr.employee_type = grouped_dtr.employee_type
AND dtr.effective_date = grouped_dtr.maxdate;
However this gives me ORA-00933, command not properly ended.
As far as I can see I'm following the suggestion as it's written. Is there a small change I need to make for this technique to work - or perhaps a different query technique which can get the most recently effective rule per each employee type?