Buchead Posted June 16, 2012 Share Posted June 16, 2012 Hi, I have a table for test results: `results` resultID year class person result What I'm attempting to do is pull out the top person from each year for a given class. I can get it pull out 1 person per year, however it's not the top result. Tried using inner queries with different join but none work. Is what I'm attempting possible or should the query be cycled through with the year specified each time? Many thanks. Quote Link to comment https://forums.phpfreaks.com/topic/264298-problem-extracting-top-result-grouping-by-year/ Share on other sites More sharing options...
fenway Posted June 16, 2012 Share Posted June 16, 2012 Try (untested) SELECT person FROM results AS r1 INNER JOIN ( SELECT MAX(result) AS result, year FROM results WHERE class = '<desiredClassValue>' GROUP BY year ) AS r2 USING( Result, year ) WHERE r1.class = '<desiredClassValue>' Quote Link to comment https://forums.phpfreaks.com/topic/264298-problem-extracting-top-result-grouping-by-year/#findComment-1354478 Share on other sites More sharing options...
Buchead Posted June 16, 2012 Author Share Posted June 16, 2012 That worked perfectly. Thank you very much. Quote Link to comment https://forums.phpfreaks.com/topic/264298-problem-extracting-top-result-grouping-by-year/#findComment-1354490 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.