Self Join Employees Table by Year
Find employees who joined in the same year as their manager.
sql
SELECT e.name AS employee_name, m.name AS manager_name FROM employees e JOIN employees m ON e.manager_id = m.id WHERE YEAR(e.created_at) = YEAR(m.created_at);
This query performs a self-join on the "employees" table to match employees with their respective managers and filters the results to include only those pairs where the year of the "created_at" timestamp is identical for both.
PromptDB can make mistakes. Please double-check responses.