Auto-Increment, Last 3?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
stickman373
Forum Commoner
Posts: 30
Joined: Mon Jul 22, 2002 10:26 am

Auto-Increment, Last 3?

Post by stickman373 »

Ihave a field called id in my mysql database and it's auto-incrementing, so I want to get the last 3 id values from the database. And some records could get deleted so it isn't always going to be records like 6,5,4. Say I deleted 4 then the the last 3 rows would be 6,5,3. How do i find each of the last 3 id values please
User avatar
RandomEngy
Forum Contributor
Posts: 173
Joined: Wed Jun 26, 2002 3:24 pm
Contact:

Post by RandomEngy »

This query will return the id's of the most recent 3 entries.

SELECT id FROM tablename ORDER BY id DESC LIMIT 0, 3
Post Reply