I have a MySQL table with the following fields:
Email, Flag1, Flag2
The question:
Is there any way i can do a select to get the last 100 inserted fields?
As i understand the table populates by adding new records with simple “insert” to the end of the table.
I have an idea how to do that in PHP+MySQL (the very ugly way: SELECT ALL RECORDS, assign to each record autoincremented ID in php loop, and get the last 100 records.)
Is there more elegant way to do that with pure MySQL?
that’s not possible, because if you don’t set a field with the timestamp or an autoincrement how will the system know the last inserted?. so you have 2 easy options.
Create a timestamp field: and when you make the order just make
select * from yourtamble order by timefield desc limit 100Create a as ID with autoincrement. The good about this is that you can have a primary key and know the exact order how the listing were inserted, the bad thing about this, is that you’ll need another field time to know when the data were insert. As the timestamp solution you could make
select * from yourtamble order by id desc limit 100