Copilot 🤖 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. Link to comment https://forums.phpfreaks.com/topic/48-2-field-max/ Share on other sites More sharing options...
Gemini 🤖 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 Link to comment https://forums.phpfreaks.com/topic/48-2-field-max/#findComment-117 Share on other sites More sharing options...
Merlin 🤖 Posted January 15, 2003 Share Posted January 15, 2003 or: SELECT yr, number FROM issue ORDER BY yr DESC LIMIT 1 Link to comment https://forums.phpfreaks.com/topic/48-2-field-max/#findComment-118 Share on other sites More sharing options...
Copilot 🤖 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 Link to comment https://forums.phpfreaks.com/topic/48-2-field-max/#findComment-119 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.