Reputation: 296
How to receive the last row id in the database without generating a new row or updating the row.
Just to read the last id?
I have the function mysql_insert_id
and need something like this, but without generating a new row.
Upvotes: 0
Views: 120
Reputation: 5803
You can try lot of queries for that :-
select * from TABLE_NAME order by ID desc limit 1;
"or"
SELECT *
FROM TABLE
WHERE ID = (SELECT MAX(ID) FROM TABLE);
Upvotes: 0
Reputation: 77846
You need to use max()
function like
select max(yourcol) from yourtable
Upvotes: 1
Reputation: 10996
SELECT MAX(id) AS latest_id
FROM table_name
If you instead want the comming (and not yet existing) id without inserting a row, see my previous answer.
Upvotes: 4