Hi,
I'm quite the newbie, but can anyone tell me how I to create a MySQL query that returns only the last three entries in a database?
Thanks.
| SitePoint Sponsor |
Hi,
I'm quite the newbie, but can anyone tell me how I to create a MySQL query that returns only the last three entries in a database?
Thanks.
Originally Posted by jjfletch
Code:SELECT * FROM table ORDER BY ID DESC LIMIT 3





That answer is not correct. It is only correct if there is a column labeled ID and the last three items are assumed to be the ones with the largest ID values.
There is no way to determine last three items as this is a database and not flat file system. if you used a timestamp for instance then you could get three latest by timestamp. but otherwise the data is not put in the database in any one order. You would have to define more specifically on what criteria (such as the ID criteria the user suggested above, but that one would have to have an auto increment ID to work correctly).
Bookmarks