I'm fairly new to SQL and I'm working on an assignement for my Uni database course. The request is to find the name of the employees that earn the minimum wage for each of the departments (jobs) in my database. The EMPLOYEES table contains name, code, job and wage for every employee.
This is the query I've written so far, and while it gives me all the right names, it throws in some more that shouldn't be there. My idea was to catch the minimum wage for each job (with the subquery, which actually seems to work fine), and then join that with the full EMPLOYEES table, to grab the names aswell. What am I doing wrong?
SELECT E.EMP_NAME
FROM EMPLOYEES AS E
INNER JOIN (SELECT MIN(WAGE)AS W
FROM EMPLOYEES
GROUP BY JOB)AS EMP
ON E.WAGE=EMP.W
ORDER BY E.JOB;