How to SELECT the last 10 rows of an SQL table which has no ID field? How to SELECT the last 10 rows of an SQL table which has no ID field? sql sql

How to SELECT the last 10 rows of an SQL table which has no ID field?


All the answers here are better, but just in case...There is a way of getting 10 last added records. (thou this is quite unreliable :) ) stillyou can do something like

SELECT * FROM table LIMIT 10 OFFSET N-10

N - should be the total amount of rows in the table (SELECT count(*) FROM table). You can put it in a single query using prepared queries but I'll not get into that.


Select from the table, use the ORDER BY __ DESC to sort in reverse order, then limit your results to 10.

SELECT * FROM big_table ORDER BY A DESC LIMIT 10


SQL tables have no implicit ordering, the order has to come from the data.Perhaps you should add a field to your table (e.g. an int counter) and re-import the data.

However that will only give the order of the import and not the data. If your data has no ordering you have to find out how to add it.

EDIT: you say

...to make sure it imported everything.

What's wrong with using row count?