0

I have to make a table of basketball players and a query which finds the player with the most experience I have tried

SELECT firstName, lastName, MAX(experience) FROM Player

but I'm assuming thats wrong.

So basically I want to find the player with the highest experience (data type set as an INT)

Thank you!! :D

APC
  • 144,005
  • 19
  • 170
  • 281
Bilal Haider
  • 99
  • 3
  • 5
  • 10
  • possible duplicate of [Fetch the row which has the Max value for a column](http://stackoverflow.com/questions/121387/fetch-the-row-which-has-the-max-value-for-a-column) – APC Apr 30 '13 at 10:38

7 Answers7

4
SELECT  firstName, 
        lastName, 
        experience
FROM    Player
WHERE   experience = (SELECT MAX(experience) FROM Player)
John Woo
  • 258,903
  • 69
  • 498
  • 492
1
SELECT  * FROM Player
WHERE experience = 
(SELECT max(experience) FROM Player)
Linga
  • 10,379
  • 10
  • 52
  • 104
1
select top 1 firstName, lastName, experience
from Player
order by experience desc;
vc 74
  • 37,131
  • 7
  • 73
  • 89
Karan Gandhi
  • 1,494
  • 2
  • 12
  • 20
0
select firstName, lastName, experience
from Player
where rownum = 1
order by experience desc;
Kevin Bowersox
  • 93,289
  • 19
  • 159
  • 189
  • this doesn't work if there are more than one players with the most experience. – dmg Apr 30 '13 at 09:16
  • -1 because this approach doesn't work at all. You have to sort first and then take the first row, not the other way round. – Frank Schmitt Apr 30 '13 at 09:36
0

The correct query is:

Select FirstName, LastName, Experience as Experience_Player
from Player
where experience = (Select MAX(experience) from Player)

Suppose you have following data:

FirstName                     LastName               Experience  
Adam                          Smit                   15  
John                          Carlos                 25  
Ibrahim                       Khan                   10  

When you would apply above mentioned query, you will get the name of Ibrahim Khan because he is the most experienced player.

And if you want to get multiple player having experience more than 10 years, just run this query

Select FirstName, LastName, experience 
from Players
where experience > 10
NeverHopeless
  • 11,077
  • 4
  • 35
  • 56
0
SELECT FIRSTNAME,LASTNAME,EXPERIENCE FROM (SELECT FIRSTNAME,LASTNAME,EXPERIENCE,DENSE_RANK() OVER (ORDER BY EXPERIENCE DESC) EXP FROM PLAYER) WHERE EXP=1;
rink.attendant.6
  • 44,500
  • 61
  • 101
  • 156
Abhijit
  • 11
  • 2
-2
select * from (
  select firstname, lastName, experience from player
  order by experience desc)
where rownum = 1
Frank Schmitt
  • 30,195
  • 12
  • 73
  • 107