sqloracle-databaseminhaving

Using the MIN function in the having clause


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);

Solution

  • How about using ROWNUM?

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