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

From: Date: Sat, 17 Feb 2001 07:58:53 +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-40297@lists.php.net to get a copy of this message
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 >

« previous php.general (#40297) next »