4WebHelp
 FAQ  •  Search  •  User Groups  •  Forum Admins  •  Smilies List  •  Statistics  •  Rules   •  Login   •  Register
Toggle Navigation Menu

 mySQL MAX Query
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic
Author Message
Iyonix
WebHelper
WebHelper


Joined: 12 Nov 2002
Posts: 82
Location: Yarm, England

PostPosted: Sun Dec 21, 2003 9:55 am (13 years, 10 months ago) Reply with QuoteBack to Top

I have a database with lots of rows in it, and each row has a field with the date in it. Date is stored as an integer of format YYYYMMDDHHMMSS, I want to SELECT using PHP and a mySQL query the maximum value of the date in any of the rows with forum id $fid, and put that value into the variable $lastpostdate

SELECT date FROM posts WHERE fid='".$fid."' HAVING date=MAX('date') LIMIT 0,1

is the query I am trying, but either that doesn't work, or I can't work out the PHP to get it into the variable I mentioned above.

Thanks, and a Merry Christmas to you all.
Iyonix

________________________________
Iyonix
OfflineView User's ProfileFind all posts by IyonixSend Personal Message
adam
Forum Moderator & Developer



Joined: 26 Jul 2002
Posts: 704
Location: UK

PostPosted: Sun Dec 21, 2003 11:41 am (13 years, 10 months ago) Reply with QuoteBack to Top

I personally would just use this query and ignore all but the first row:
Code:
SELECT date FROM posts WHERE fid = '".$fid."' ORDER BY date DESC

that may not be the most efficient way of doing it, but it should work

________________________________
It's turtles all the way down...
OfflineView User's ProfileFind all posts by adamSend Personal MessageVisit Poster's Website
jayant
Team Member



Joined: 07 Jan 2002
Posts: 262
Location: New Delhi, India

PostPosted: Tue Dec 23, 2003 8:36 am (13 years, 10 months ago) Reply with QuoteBack to Top

Code:
SELECT date FROM posts WHERE fid = '".$fid."' ORDER BY date DESC LIMIT 1

and the query will be even more efficient if one you have created an index on teh date field.

________________________________
Jayant Kumar
Member of the 4WebHelp Team
Nibble Guru - Computing Queries Demystified
GZip/ Page Compression Test
OfflineView User's ProfileFind all posts by jayantSend Personal MessageVisit Poster's WebsiteYahoo MessengerMSN Messenger
Display posts from previous:      
Post New TopicReply to Topic
View Previous Topic Print this topic View Next Topic


 Jump to:   




You cannot post new topics in this forum.
You cannot reply to topics in this forum.
You cannot edit your posts in this forum.
You cannot delete your posts in this forum.
You cannot vote in polls in this forum.


Page generation time: 0.049561 seconds :: 17 queries executed :: All Times are GMT
Powered by phpBB 2.0 © 2001, 2002 phpBB Group :: Based on an FI Theme