Find Oldest Employee per Department Query

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

sql

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

This query uses a correlated subquery to identify the minimum hire_date for each department_id and returns the corresponding employee records.

PromptDB can make mistakes. Please double-check responses.