我需要这个查询-更新倒数第二条记录。
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附近出了什么问题?
发布于 2012-04-04 17:02:36
标准更新协议
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尝试一下会对你有真正的帮助,代码测试过了。update中的Limit只能使用行计数,而不能使用1,1等。
发布于 2012-04-04 17:05:26
LIMIT可以与UPDATE一起使用,但只能与行数一起使用。请参阅this。
LIMIT子句对可以更新的行数进行限制。
所以这个查询应该是有效的-
UPDATE
changes
SET
checked = ''
WHERE item_id = 119898
AND TYPE = 'example_edit'
AND checked != 'restored'
ORDER BY id DESC
LIMIT 1;https://stackoverflow.com/questions/10007953
复制相似问题