简体   繁体   中英

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) :

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

Trying to do this in Maria though returns the following error :

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?

I'd expect this to be a bit more efficient than your answer with the LEFT JOIN / IS NULL construction:

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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