RE: [PHP] Can I select only the newest record?

From: Date: Sat, 17 Feb 2001 11:12:21 +0000
Subject: RE: [PHP] Can I select only the newest record?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-40315@lists.php.net to get a copy of this message
I wonder, if LAST_INSERT_ID will work in here... I know it works when on the same file was an insertion.. but will it return you the last ever inserted id, say a week ago? I feel like it won't, but don't know for sure... try it... Sincerely, Maxim Maletsky Founder, Chief Developer PHPBeginner.com (Where PHP Begins) maxim@phpbeginner.com www.phpbeginner.com -----Original Message----- From: ..s.c.o.t.t.. [mailto:scott@furt.com] Sent: Saturday, February 17, 2001 4:59 PM To: Php-General Subject: RE: [PHP] Can I select only the newest record? there are two ways that come to mind of doing this if you're using some kind of auto-incrementing field (not necessarily AUTO_INCREMENT, but any field that increases [or decreases] with time) this will select the entire row, but limit the query to only return 1 result (and depending on how your order, this result could be the highest/lowest value of the field): (to get highest value of field id) SELECT * FROM mytable ORDER BY id ASC LIMIT 1; (to get lowest value of field id) SELECT * FROM mytable ORDER BY id DESC LIMIT 1; PS: there's probably a more efficient way to do it, but this is what came to mind at the moment... > -----Original Message----- > From: Brian Drexler [mailto:bdrexler@mail.precisionwd.com] > Sent: Friday, February 16, 2001 20:22 > To: Php-General > Subject: [PHP] Can I select only the newest record? > > > Using PHP3/MySQL, is there a way I can select only the newest record from a > MySQL table. I have a datetime field and an Auto_incremented field. Anyone > got any ideas??? > > Brian Drexler > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net For additional commands, e-mail: php-general-help@lists.php.net To contact the list administrators, e-mail: php-list-admin@lists.php.net

« previous php.general (#40315) next »