I would like to display the player with the highest salary.
select max(Salary) as highest_salary, p.[Last name]
from tbl_PlayersTable as p, tbl_team as t
where p.Team = t.TeamID
and TeamID = 1000
Group by p.[Last name]
The output is:
highest_salary Last Name
8000 Bosh
7000 Wade
6000 James
I just want to display (8000 Bosh since he is the player with highest salary).
You did't need
MAX
norGROUP BY
, just useTOP 1
withORDER BY Salary DESC
. Something like this:You are grouping values there (see Group By in the end) and so your max function calculates Max value per group. If you wand an absolute max value, remove the grouping.
You will need to take the top 1 value
No need for
group by
or evenmax
:Because you use
group by p.[Last name]
so that the query will getmax(Salary)
for each distinctLast name
it found. So if you want to get themax(Salary)
base on all ofLast name
, you must removegroup by