[sql] SQL query: Delete all records from the table except latest N?

What about :

SELECT * FROM table del 
         LEFT JOIN table keep
         ON del.id < keep.id
         GROUP BY del.* HAVING count(*) > N;

It returns rows with more than N rows before. Could be useful ?