Using the MIN function in the having clause

Sindu_ picture Sindu_ · Nov 4, 2013 · Viewed 35k times · Source

I want to get the name of the employee who has the minimum salary. Is there a way to do this using only one query? I have given my query below, it doesn't work because the having clause requires a condition. Is there any way to give a condition in the having clause that will retreive the employee name with the minimum salary?

SELECT first_name,min(salary) as "sal"
FROM Employees
GROUP BY first_name 
having min(salary);

Answer

MarcinJuraszek picture MarcinJuraszek · Nov 4, 2013

How about using ROWNUM?

SELECT *
FROM(SELECT first_name, salary
     FROM Employees
     ORDER BY salary
) WHERE ROWNUM = 1