获取最后插入记录的值

Get the value of the last inserted record

我正在尝试使用 preparedStatement 获取 table 中最后插入的行的 stop_name。我怎样才能得到最后插入的那个?

感谢任何帮助。

行为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
);

您可以试试这个查询:

select stop_name from behaviour where created_at in (select max(created_at) from behaviour)

另一个解决方案:

select stop_name from behaviour order by behaviour_id desc limit 1;