Hello All I have a mysql table and I want to fetch last inserted five records from the table. Can anyone tell me how can I do this using query?
SELECT column_names FROM my_table ORDER BY id_column LIMIT COUNT(id_column) - 5, 5 Code (markup): Something like that should do it
provided you have an integer id column that increments with every insertion otherwise tag each row with a date and sort on that
ordering however doesnt, especially if the column doesnt exist all the solutions above assume the existance of this column
If there is no ID column or a date column there would be no way to do any date based or logical ordering at all. In most situations it would be irrational to design a database table without some chronological identifier.
"I want to fetch last inserted five records" I don't know about you guys, but that infers a need for a "chronological identifier" to me.