Selecting the last row

I need to select the last(latest) row in a table, what’s the query going to look like. Do I need to first count how many rows, then use the number in a select query? This seems ineffficient to me.

“latest” makes sense only in the context of MAX(some_datetime_column)

does your table gots something like that?

No, by latest i just mean the very last row.

unfortunately, there is no such concept

rows in database tables do not have a position

everything must be accomplished by reference to column values

You are kinda right, i found what i was looking for is just a simple:
select * from table order by id desc limit 1

the reference is to the id column - like you said

that’ll work (most of the time)

may i ask why you need to query out the latest row?

i need to query the latest row so i can use the values obtained
in the next row - a kinda “balance carried over” thing, i’m working
on a ledger system.

that could get you in trouble

the “latest” row might not be for the same account

do a search on race condition

you’re probably going to want to use transactions

Thanks.

Fortunately, it’s not going to be a multi-user system,
it’s an offline software developed with php/mysql accessed
only by the admin.