Java – how do I retrieve the last inserted value in my database?

Anyone can tell me about the query for the last inserted value in the database column

The problem is that after using ASC or DESC, the inserted value can be placed in the internal row of the database, so I can't use this method If anyone has a solution, please let me know

Solution

You will need to use the timestamp data column to track the insertion time Unfortunately, the use of auto - incrementing primary keys will not work in this case due to inherent competitive conditions Simply add the entry timestamp as a data column and use order by time_ Stamp desc limit 1 gets the last record If you feel really defensive, the purpose is to include the unique condition of the original insert call in the where clause (that is, where id = x and key = y)

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>