Find Newest Employee Per Department Query

Find the newest employee in each department based on hire date.

sql

SELECT department_id, name, hire_date FROM employees e1 WHERE hire_date = ( SELECT MAX(hire_date) FROM employees e2 WHERE e1.department_id = e2.department_id );

This query uses a correlated subquery to identify the maximum hire_date for each department_id and filters the employees table to return the records matching those dates.

PromptDB can make mistakes. Please double-check responses.