| 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.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Akkiraju IvaturiPosted Sep 11, 2012, 9:39 PM
http://www.c-sharpcorner.com/UploadFile/akkiraju/handling-concurrency-data-insertion-operations-in-mysql/
Vineet Kumar SainiPosted Sep 10, 2012, 6:48 AM
Akkiraju IvaturiPosted Sep 4, 2012, 8:51 AM
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.