faqts : Computers : Programming : Languages : PHP : Database Backed Sites : General

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

27 of 31 people (87%) answered Yes
Recently 7 of 10 people (70%) answered Yes

Entry

What fields do I need to be able to query for the latest changes to a table?
How can I query a table to get the latest updates and new records?
How do I get the latest changes using an autoincrement and a timestamp field?

Apr 12th, 2000 10:41
michael kimsal, Niketan Pandit, Onno Benschop, unknown unknown,


Assuming the timestamp field is called 'updatetime' and the serial 
number is called 'pkey':
select * from <tablename> order by updatetime DESC limit 0,5
will give you the most recent 5 entries by 'updatetime'
select * from <tablename> order by pkey DESC limit 0,5
will give you the most recent 5 entries by the autoincrement field.
The 'limit' function is in MySQL and (I believe) Oracle, but 
I don't remember seeing it in MSSQL7 or 6.5.
You didn't say what datbase you were using, so I assumed MySQL.