为什么我在mysql中删除最后一条记录查询时出现语法错误?

时间:2014-02-25 05:12:32

标签: mysql

修改 请忽略 - 我是在深夜做的,因为它没有注意到语法错误

我正在尝试删除最后一条记录,但是我收到语法错误。我的查询中的错误在哪里?

DELETE t1 FROM mydb.PauseResume AS t1
JOIN (SELECT `timestamp` FROM mydb.PauseResume ORDER_BY `timestamp` DESC LIMIT 1) AS t2
WHERE `t1`.`timestamp` = `t2`.`timestamp`

3 个答案:

答案 0 :(得分:3)

ORDER_BY应为ORDER BY。没有下划线。

答案 1 :(得分:1)

我想你应该点击的是:

DELETE t1.* FROM mydb.PauseResume AS t1
JOIN (SELECT `timestamp` FROM mydb.PauseResume ORDER BY `timestamp` DESC LIMIT 1) AS t2
WHERE `t1`.`timestamp` = `t2`.`timestamp`

有关MySQL语法的详细信息,请查看:

https://dev.mysql.com/doc/refman/5.0/en/sql-syntax.html

答案 2 :(得分:0)

在JOIN中你也需要一个ON语句。您尝试使用WHERE子句执行此操作。

应该是

DELETE t1 FROM mydb.PauseResume AS t1
(SELECT `timestamp` FROM mydb.PauseResume ORDER BY `timestamp` DESC LIMIT 1) AS t2
ON (`t1`.`timestamp`=`t2`.`timestamp`);