Jump to content

grabbing most recent record from MySQL


bcamp1973

Recommended Posts

I want to grab the most recently added record from a table in MySQL.  is it best to query for all records and determine what's newest using PHP? If so, can someone point me in the right direction?  Otherwise, is there a MySQL function that does this? My googling hasn't been much help and i'm not having any luck with the MySQL online documentation :(
Link to comment
https://forums.phpfreaks.com/topic/16829-grabbing-most-recent-record-from-mysql/
Share on other sites

You cant know which record is the most recent, unless you have a "date" field (either a time stamp, or just a date), or an auto increment field (numbering the rows).

You most likely have a auto increment column (let's call it ID). In this case your query will be:
"SELECT * FROM `table_name` ORDER BY ID DESC LIMIT 1"

Orio.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.