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 Quote Link to comment 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 Quote Link to comment 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! Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.