Thursday, January 7, 2016

Select Last Row of MySQL Table (Or the very first entry to the table)

Here are two ways where the table index is auto-incremented:

select * from myTable where myIndex = (select MAX(myIndex) from myTable); 

select * from myTable order by myIndex asc limit 1;

Which one is more efficient?

By the way, one can also select the latest entries from a MySQL table with:

select * from myTable order by myIndex desc limit 4; 

No comments:

Post a Comment