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);
Try this solution, inspired from here:
How about using
ROWNUM
?If you need the employee with the lowest salary why don't you use Order By ..
With a single
SELECT
statement:SQLFIDDLE
However, if there are multiple people with the same minimum salary then this will only get the one with the name which is first alphabetically.
You can get all the names, but it does require multiple
SELECT
statements:But having multiple
SELECT
statements isn't a bad thing.SQLFIDDLE