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

后端 未结 13 1451
灰色年华
灰色年华 2020-12-15 17:38

I have an MySQL table with 25000 rows.

This is an imported CSV file so I want to look at the last ten rows to make sure it imported everything.

However, sinc

13条回答
  •  情书的邮戳
    2020-12-15 18:05

    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 :) ) still you 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.

提交回复
热议问题