How can I SELECT
the last row in a MySQL table?
I'm INSERT
ing data and I need to retrieve a column value from the previous row.
There's an auto_increment
in the table.
How can I SELECT
the last row in a MySQL table?
I'm INSERT
ing data and I need to retrieve a column value from the previous row.
There's an auto_increment
in the table.
If you want the last of all the rows in the table, then this is finally the time where
MAX(id)
is the right answer! Kind of:You can use an
OFFSET
in aLIMIT
command:in case your table has 100 rows this return the last row without relying on a primary_key
on tables with many rows are two queries probably faster...