I have a LoginTime table :
id | user_id | datetime
1 | 1 | 2011-01-19 18:51:01
2 | 1 | 2011-01-19 18:51:02
3 | 1 | 2011-01-19 18:51:03
4 | 1 | 2011-01-19 18:51:04
5 | 1 | 2011-01-19 18:51:05
6 | 1 | 2011-01-19 18:51:06
7 | 1 | 2011-01-19 18:51:07
8 | 1 | 2011-01-19 18:51:08
9 | 1 | 2011-01-19 18:51:09
10 | 2 | 2011-01-19 18:51:10
I want to save only the last 5 (in the "datetime" columns) and delete all previous records, where user_id=1
Is it possible to achieve this with a single mysql query?
source
share