Delete N number of old records from table in mysql

前端 未结 4 1943
攒了一身酷
攒了一身酷 2021-02-10 03:25

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             


        
4条回答
  •  孤城傲影
    2021-02-10 03:56

    I believe this will work...

    DELETE FROM LoginTime WHERE id IN (
         SELECT id
         WHERE user_id = 1
         ORDER BY datetime DESC
         LIMIT 0, 5
    )
    

提交回复
热议问题