I have a LoginTime table like this:
id | user_id | datetime
1 | 1 | 2011-01-19 18:51:01
2 | 1 | 2011-01-19 18:51:02
3 | 1
delete LoginTime
from
LoginTime
left join
(
select id
from LoginTime
where user_id=1
order by `datetime` desc
limit 5
) as not_to_delete
on LoginTime.id=not_to_delete.id
where
not_to_delete.id is null;
PS: please don't use CamelCase for table name, and avoid using reserved keywords for the column name