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. 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>' 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. 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
Archived
This topic is now archived and is closed to further replies.