Home > Software engineering >  How to SELECT data 30 last data from ID
How to SELECT data 30 last data from ID

Time:10-14

Now my ID is AUTO_INCREMENT and recive data 1 time per day. But I have to select the last 30 rows of data to display.
In the sql.
"SELECT * FROM table WHERE id BETWEEN (SELECT MAX(id)-30) AND (SELECT MAX(id))"

but it showing all the data. What did i do wrong please guide me.

CodePudding user response:

If you want to select last 30 data rows you can use following query.

select * from tbl_name order by id desc limit 30;
  • Related