WHY DOES MAX FUNCTION IN SQL RETURN MULTIPLE VALUES

Jayden Bell

Total Post:110

Points:774
Posted by  Jayden Bell
 1346  View(s)
Ratings:
Rate this:
Hi Everyone!

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

Thanks in advance!
  1. AVADHESH PATEL

    Post:604

    Points:4228
    Re: Why does max function in sql return multiple values

    Hi Jayden!


    You did't need MAX nor GROUP BY, just use TOP 1 with ORDER BY Salary DESC. Something like this:

    select TOP (1) Salary as highest_salary, p.[Last name]
    from tbl_PlayersTable as p, tbl_team as t
    where p.Team = t.TeamID
     and TeamID = 1000
    ORDER BY Salary  DESC

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!