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 :( Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.