Jump to content


Photo

grabbing most recent record from MySQL


  • Please log in to reply
1 reply to this topic

#1 bcamp1973

bcamp1973
  • Members
  • PipPipPip
  • Advanced Member
  • 133 posts

Posted 07 August 2006 - 08:59 PM

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

#2 Orio

Orio
  • Staff Alumni
  • Advanced Member
  • 2,491 posts

Posted 07 August 2006 - 09:14 PM

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.
Think you're smarty?

(Gone until 20 to November)




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users