Reputation: 2380
I am trying to get the stop_name
of the last inserted row in the table with preparedStatement. How can I get the last inserted one?
I appreciate any help.
behavoiur table:
CREATE TABLE IF NOT EXISTS behaviour(
behaviour_id INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
mac VARCHAR(30) NOT NULL,
stop_name VARCHAR(30) NOT NULL,
stop_distance INT(11) NOT NULL,
speed INT(11) NOT NULL,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);
Upvotes: 0
Views: 58
Reputation:
You may try this query:
select stop_name from behaviour where created_at in (select max(created_at) from behaviour)
Upvotes: 2
Reputation: 4774
Another solution:
select stop_name from behaviour order by behaviour_id desc limit 1;
Upvotes: 0