2012-01-06 7 views

risposta

36
DELETE FROM table ORDER BY the field DESC|ASC limit 100 
1
SET @first = 1; 
delete from mytable 
where primKey in (select 1 
        from myTable 
        order by 
        CASE WHEN @first = 1 THEN primKey END ASC, 
        CASE WHEN @first <> 1 THEN primKey END DESC 
        limit 100) 
+0

Sono abbastanza sicuro mysql non consentono limite nelle query interne. –

+0

@ItayMoav, sono abbastanza sicuro del contrario. – Johan

+0

@Johan ci sbagliamo entrambi, dovrei aver dichiarato le versioni in cui questa restrizione vale (5.1 e sotto, se la mia memoria serve) e devi fare lo stesso. Se ritieni che 5.1 supporti ciò, sei più che benvenuto a testarlo. –

9

per il primo 100,

DELETE FROM table ORDER BY <field> ASC limit 100 

e per l'ultimo 100,

DELETE FROM table ORDER BY <field> DESC limit 100 
Problemi correlati