How to select last Mysql table record with last or another command?

Asked

Viewed 12,463 times

0

How to select last record from Mysql table with last or another command

For example:

select last registro from tabela where coluna = 23;

I tried with this code but it didn’t work.

  • Which is the auto-increment item in this table?

3 answers

3

If the table has a field auto increment ordain decreasing and limit the result in 1 line.

SELECT registro FROM tabela WHERE coluna = 23 ORDER BY id DESC limit 1;

2

It’s been a long time since that question, but follow the answer.

SELECT MAX(id) as maxId FROM table

-2

SELECT MAX(id) as maxId FROM table 

I think this type of consultation brings the highest value and not the last!

  • Yes, that’s correct. But that’s the idea, in a table with the field id(auto_increment), however you suffer deletions of records, will always get the highest value of the column id(auto_increment)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.