SELECT * FROM myTable WHERE myDateValue IN (SELECT MAX(myDateValue) FROM myTable) LIMIT 1
The limit makes sure you just get one (in the event that there are multiple entries with the same date and they happen to be the last ones)
From: "Tucker, David" <[EMAIL PROTECTED]> Reply-To: BYU Unix Users Group <[EMAIL PROTECTED]> To: "Uug (E-mail)" <[EMAIL PROTECTED]> Subject: [uug] SQL help (most recent) Date: Mon, 20 Oct 2003 11:09:02 -0700
I'm creating a simple mySQL database that is being populated by a perl
script. Each entry will corresponds to an event that is happening on
another machine. I'm looking for an SQL query that will return the most
recent entry and I have no way of knowing when that might have been. It may
have been two hours ago, or two weeks.
The only way I can think of is to ask for the list to be sorted and take
the first row, but this seems wrong in every way, especially once the list
starts to grow.
Any ideas?
dave
____________________ BYU Unix Users Group http://uug.byu.edu/ ___________________________________________________________________ List Info: http://uug.byu.edu/cgi-bin/mailman/listinfo/uug-list
_________________________________________________________________
Concerned that messages may bounce because your Hotmail account has exceeded its 2MB storage limit? Get Hotmail Extra Storage! http://join.msn.com/?PAGE=features/es
____________________
BYU Unix Users Group http://uug.byu.edu/ ___________________________________________________________________
List Info: http://uug.byu.edu/cgi-bin/mailman/listinfo/uug-list
