欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

删除前100条数据,根据主键ID排序。

程序员文章站 2022-06-12 13:36:55
...
sql语句怎么写啊?
delete from visitrecord where id in (select top 100 from visitrecord order by id asc)

这样写有什么错误吗?


回复讨论(解决方案)

delete from visitrecord where id in (select id from visitrecord order by id asc limit 100)

delete from visitrecord limit 100

delete from visitrecord where id in (select id from visitrecord order by id asc limit 100)

This version of MySQL doesn't yet support 'LIMIT & IN/ALL/ANY/SOME subquery

delete from visitrecord where id in (select top 100 from visitrecord order by id asc)
你的这个写法是sqlserver的

mysq写法如下
delete from visitrecord where id in (select id from visitrecord order by id asc limit 100);

都是大神啊,我轻飘飘的路过~~~