0

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 ); 
3
  • 2
    Are you asking help with writing the query or writing the code? Commented Jun 22, 2015 at 9:34
  • With writing the query Commented Jun 22, 2015 at 9:36
  • Which db are you using? Commented Jun 22, 2015 at 10:03

2 Answers 2

2

You may try this query:

select stop_name from behaviour where created_at in (select max(created_at) from behaviour) 
Sign up to request clarification or add additional context in comments.

Comments

0

Another solution:

select stop_name from behaviour order by behaviour_id desc limit 1; 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.