Mahesh Singh
Mahesh Singh

Reputation: 38

How to get last id?

I am facing difficulty to get the last inserted field in.

selct scope identity();

SELECT *
FROM Person
ORDER BY PersonID DESC
LIMIT 1

Upvotes: 0

Views: 71

Answers (1)

PoulsQ
PoulsQ

Reputation: 2016

For MySQL, just after the insertion you can try that kind of solution :

echo mysql_insert_id($mysql);

If you come back later and want the last ID, it's more complecated ... You can use your solution, but nothing tell you that an other ID will be inserted between the moment of the return of the query and what you will do with it ...

Upvotes: 1

Related Questions