Jump to content

Archived

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

bcamp1973

grabbing most recent record from MySQL

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 :(

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

×

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.