What's the most efficient way to select the last n rows in a table without changing the table's structure?

后端 未结 8 1851
天命终不由人
天命终不由人 2020-12-10 02:25

What\'s the most efficient way to select the last n number of rows in a table using mySQL? The table contains millions of rows, and at any given time I don\'t know how large

8条回答
  •  一生所求
    2020-12-10 02:42

    Here you can change table name and column name according your requirement . if you want to show last 10 row then put n=10,or n=20 ,or n=30 ...etc according your requirement.

    select * from (select * from employee Order by emp_id desc limit n) a Order by emp_id asc;

提交回复
热议问题