简体   繁体   English

在MariaDB中删除超过900行的所有内容

[英]Remove anything above 900 rows in MariaDB

This works in Mysql, but it seems that the syntax for MariaDB is different, I am trying to remove anything above the first 900 returned rows (LIMIT 900) : 这在Mysql中有效,但似乎MariaDB的语法不同,我正在尝试删除返回的前900行(LIMIT 900)以上的所有内容:

DELETE FROM cronschedule NOT IN (SELECT * FROM cronschedule LIMIT 900);

Trying to do this in Maria though returns the following error : 在Maria中尝试执行此操作会返回以下错误:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that 
corresponds to your MariaDB server version for the right syntax to use near 
'NOT IN (SELECT * FROM cronschedule LIMIT 900)' at line 1

So how would I do this in Maria? 那么我将如何在Maria做到这一点?

I'd expect this to be a bit more efficient than your answer with the LEFT JOIN / IS NULL construction: 我希望这比使用LEFT JOIN / IS NULL构造的答案更有效:

DELETE  cr.*
FROM    cronschedule cr
    JOIN
        (
        SELECT  id
        FROM    cronschedule ii
        ORDER BY
                id ASC
        LIMIT 1 OFFSET 900
        ) i2
ON      cr.id >= i2.id ;

This seems to work 这似乎有效

DELETE  cr.*
FROM    cronschedule cr
LEFT JOIN
        (
        SELECT  id
        FROM    cronschedule ii
        ORDER BY
                id ASC
        LIMIT 900
        ) i2
ON      cr.id = i2.id
WHERE   i2.id IS NULL;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM