justravis Posted January 15, 2003 Share Posted January 15, 2003 I have a table of years and numbers that refer to seasons in another table. It looks something like this: yr number 2002 2 2003 1 I need to create a query that selects the latest yrnumber COMBO. In this case, it would be 2003, 1. Here is what I have tried: SELECT MAX(yr), MAX(number) FROM issue returned 2003, 2 SELECT MAX(yr), MAX(number) FROM issue WHERE yr=MAX(yr) SELECT yr, number FROM issue WHERE yr=MAX(yr) AND number=MAX(number) Both returned error \"Invalid use of group function\" Any other ideas? I know mysql does not support sub-queries, so do I have to use two? Sorry to bug you on a seemingly trivial issue, but I TRY to always learn how to do things the in the best and most efficient manner. Quote Link to comment https://forums.phpfreaks.com/topic/48-2-field-max/ Share on other sites More sharing options...
Uranium-235 Posted January 15, 2003 Share Posted January 15, 2003 I\'m taking a shot in the dark here but why not... SELECT yr, number FROM issue WHERE (MAX(yr) AND MAX(number)) I always like to put () around any AND/OR statements just to be safe. I think it will work without it though Quote Link to comment https://forums.phpfreaks.com/topic/48-2-field-max/#findComment-117 Share on other sites More sharing options...
effigy Posted January 15, 2003 Share Posted January 15, 2003 or: SELECT yr, number FROM issue ORDER BY yr DESC LIMIT 1 Quote Link to comment https://forums.phpfreaks.com/topic/48-2-field-max/#findComment-118 Share on other sites More sharing options...
justravis Posted January 15, 2003 Author Share Posted January 15, 2003 Why didnt\'t I think of that? first sugestion didnt work..2nd one did...thanx Quote Link to comment https://forums.phpfreaks.com/topic/48-2-field-max/#findComment-119 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.