| ID | Name | Address | Qualification |
| .. | .. | .. | .. |
| .. | .. | .. | .. |
| .. | .. | .. | .. |
I want to fetch data of latest id from this table. Please tell me anyone how to do this ? Please help me ?
Thanks.
| ID | Name | Address | Qualification |
| .. | .. | .. | .. |
| .. | .. | .. | .. |
| .. | .. | .. | .. |
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Akkiraju IvaturiRank #473 · 5.3K reputationPosted Sep 4, 2012, 4:51 AM EDT
select * from table order by ID desc limit 1
Or there is a function called LAST_INSERT_ID(). This function gets the last inserted id with in the current session and works well in concurrency mode. This is equivalent to SCOPE_IDENTITY in Sql Server. If you insert a record and its ID is 7 and some other user at the same inserted a record and it is 8 then you will still get the details of ID = 7 only.
select * from table where ID = LAST_INSERT_ID()
Just for information:
There is a function in MySQL for the last inserted ID mysql_insert_id(). But if it is in concurrent mode this will fetch you the last inserted record in whole insertions made by different users.
In this case you would be getting the details of id = 8 as it was the latest inserted record.
Use whatever is appropriate for your requirement.
Let me know if you have any questions.
Vineet Kumar SainiRank #257 · 9.8K reputationPosted Sep 10, 2012, 2:48 AM EDT
Akkiraju IvaturiRank #473 · 5.3K reputationPosted Sep 11, 2012, 5:39 PM EDT
http://www.c-sharpcorner.com/UploadFile/akkiraju/handling-concurrency-data-insertion-operations-in-mysql/