Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQL - Select name of the person with highest salary

Tags:

sql

select

max

I have a table called workers which includes a few persons by their names, their salary and their working station. The table looks something like the following:

|Name|Station|Salary|
|Kyle|1      |2200  |
|Lisa|2      |2250  |
|Mark|3      |1800  |
|Hans|4      |1350  |

This might sound like a very obvious beginner question but I cannot get it work. I would like to select the name of the person with the highest salary. Thank you for reading, and have a nice one.

like image 752
user3691006 Avatar asked May 30 '14 14:05

user3691006


2 Answers

Select name 
from table 
where salary = (select max(salary) from table)

I dont know if you want to include ties or not (if two people have the same salary and it is the max salary.

What this does is find the max salary and then uses that in the query to find all people with that salary. You will need to replace the word table with whatever your table name is.

like image 143
gh9 Avatar answered Oct 20 '22 04:10

gh9


Try this

SELECT top 1 Name
FROM tableName
ORDER BY Salary DESC
like image 45
Sid M Avatar answered Oct 20 '22 02:10

Sid M