bcamp1973 Posted August 7, 2006 Share Posted August 7, 2006 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 More sharing options...
Orio Posted August 7, 2006 Share Posted August 7, 2006 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. Link to comment https://forums.phpfreaks.com/topic/16829-grabbing-most-recent-record-from-mysql/#findComment-70829 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.