MYSQL query help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
wreed
Forum Newbie
Posts: 12
Joined: Wed Dec 18, 2002 12:12 pm
Location: Butler, NJ
Contact:

MYSQL query help

Post 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)
ReDucTor
Forum Commoner
Posts: 90
Joined: Thu Aug 15, 2002 6:13 am

Post by ReDucTor »

Code: Select all

SELECT * FROM weekly_rankings WHERE team = 'islanders' ORDER BY week DESC LIMIT 1
wreed
Forum Newbie
Posts: 12
Joined: Wed Dec 18, 2002 12:12 pm
Location: Butler, NJ
Contact:

Post by wreed »

Oh man never thought of doing it that way, thank you very much worked like a champ!
Post Reply