我有一个这样的 MySql 表,
Session_Id Subscriber_Id 状态 ------------------------------------------- abc 1234 开始 bcd 1235 开始 bcd 1235 完成
而且我需要删除状态为“已开始”的行,只有在后面跟着“完成”。这是一个巨大的表,所以我一次要删除 1000 条记录。
我阅读了一些类似的线程, Multiple-table DELETE LIMIT , DELETE FROM `table` AS `alias` ... WHERE `alias`.`column` ... 为什么语法错误?
并尝试了以下查询,
mysql> delete a.* from FSESSION as a, FSESSION as b where a.status='Started' and b.status='Finished' and a.session_id=b.session_id limit 1000;
ERROR 1064 (42000): 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 'limit 1000' at line 1 ----> If I remove 'limit' this works
mysql> DELETE FROM v USING `FSESSION` AS v WHERE status = 'Started' and exists(select 0 from FSESSION t where t.status='Finished' and v.session_id=t.session_id) limit 1000;
ERROR 1064 (42000): 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 'limit 1000' at line 1 ---->
即使删除限制也不起作用。
我使用 MySql 版本 5.1.56-ndb-7.1.15。请提出一种方法来做到这一点。谢谢!