Jump to content

Archived

This topic is now archived and is closed to further replies.

justravis

2 Field Max

Recommended Posts

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.

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
Share on other sites

or:

 

SELECT yr, number FROM issue ORDER BY yr DESC LIMIT 1

Share this post


Link to post
Share on other sites

Why didnt\'t I think of that? first sugestion didnt work..2nd one did...thanx

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.