JohnJSal Posted August 30, 2006 Share Posted August 30, 2006 Hi everyone. I have a question which seems like it should be painfully easy to answer, but I can't figure it out. I've tried several different queries, and they either return too much information, or they don't work.Here's the situation: I'm using a baseball database and am working with a single table called Batting. What I'd like to do is display the playerID and RBI columns for the player with the most RBIs in the 2005 (yearID). I've tried combinations of max(RBI) and playerID, but then I have to use a GROUP BY clause, which displays more than I want.So I'm hoping someone can help me. This seems like a very basic thing to do, but I'm having trouble working with a 'normal' column like playerID and an aggregate like max(RBI).Thanks,John Link to comment https://forums.phpfreaks.com/topic/19169-newbie-question-about-selecting-a-single-data-entry/ Share on other sites More sharing options...
AndyB Posted August 30, 2006 Share Posted August 30, 2006 SELECT playerID, RBI from Batting WHERE yearID = '2005' ORDER by RBI DESC LIMIT 1 Link to comment https://forums.phpfreaks.com/topic/19169-newbie-question-about-selecting-a-single-data-entry/#findComment-82936 Share on other sites More sharing options...
JohnJSal Posted August 30, 2006 Author Share Posted August 30, 2006 [quote author=AndyB link=topic=106273.msg424797#msg424797 date=1156953145]SELECT playerID, RBI from Batting WHERE yearID = '2005' ORDER by RBI DESC LIMIT 1[/quote]Hmm, interesting! I guess I was on the wrong track with max(RBI). Thanks! Link to comment https://forums.phpfreaks.com/topic/19169-newbie-question-about-selecting-a-single-data-entry/#findComment-82939 Share on other sites More sharing options...
AndyB Posted August 30, 2006 Share Posted August 30, 2006 No, you were on the right track but my SQL skills are minimal. Link to comment https://forums.phpfreaks.com/topic/19169-newbie-question-about-selecting-a-single-data-entry/#findComment-82940 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.