Page 1 of 1

MYSQL query help

Posted: Thu Feb 06, 2003 9:16 am
by wreed
I am running this query and have problems...

Code: Select all

SELECT * FROM weekly_rankings WHERE team = 'islanders' AND week = 3
But what I want to do is make it so I dont have to change the week area when I add a new week to the db, so in theory I want it to search the db and pull out the latest number in the week field, which it happens to be 3 right now, return that and the fields, rank, team, comment and record, but I seem to have a hard time using the MAX option.....any ideas? Here is a query that would work with SQL but not MYSQL....

Code: Select all

select * from weekly_rankings where
team ='islanders' and week = (select max (week) from weekly_rakings)

Posted: Thu Feb 06, 2003 9:22 am
by ReDucTor

Code: Select all

SELECT * FROM weekly_rankings WHERE team = 'islanders' ORDER BY week DESC LIMIT 1

Posted: Thu Feb 06, 2003 9:25 am
by wreed
Oh man never thought of doing it that way, thank you very much worked like a champ!