1

我需要这个查询 - 最后更新一条记录。

UPDATE changes SET checked='' WHERE item_id = 119898 AND type = 'example_edit' AND checked != 'restored' ORDER BY id DESC LIMIT 1, 1

数据库回声:

#1064 - You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near ' 1' at line 1

1附近有什么问题?

4

2 回答 2

0

标准更新状态

 UPDATE [LOW_PRIORITY] [IGNORE] table_reference
        SET col_name1={expr1|DEFAULT} [, col_name2={expr2|DEFAULT}] ...
        [WHERE where_condition]
        [ORDER BY ...]
        [LIMIT row_count]

对于你的情况试试这个

UPDATE changes SET checked='' WHERE item_id = 119898 AND type = 'example_edit' AND checked != 'restored' ORDER BY id DESC LIMIT 1

试试吧,它真的会帮助你,代码测试。更新限制只能使用行计数而不是 1,1 等。

于 2012-04-04T09:02:35.910 回答
0

LIMIT 可以与 UPDATE 一起使用,但只能与行数一起使用。参考这个

LIMIT 子句对可以更新的行数进行了限制。

所以这个查询应该工作 -

 UPDATE 
  changes 
SET
  checked = '' 
WHERE item_id = 119898 
  AND TYPE = 'example_edit' 
  AND checked != 'restored' 
ORDER BY id DESC 
LIMIT 1;
于 2012-04-04T09:05:25.530 回答