Rahul Gupta Rahul Gupta - 5 months ago 9
MySQL Question

get latest data from table

I am using jdbc to insert and getvalues form my database.
Suppose my sql table is like this-

NAME | STATE
x in
y in
z in
x out
y out
z out
x in
y in


As you can see there are similar values in the above table. I know how to normally get the value from table but i want to get the most recent added value of lets say 'z' which was added to the table or the last entry of z from the above table how can i get it?
Another column of type timestamp is there but when you are getting the value you only have name 'z' you don't know when the last entry was in the table

Answer
SELECT  * FROM TABLE ORDER BY `timestamp` DESC LIMIT 1