请教一个限制条件的删除语句的问题

神的理想 2013-12-12 11:27:07
我想删除按时间排序后,排在20条记录之前的老记录,用下面的语句都有问题,不知道是哪儿有问题?
第一条 执行有警告,在程序里直接报错。第二条是直接的语法错误

delete from ut_consign where sale_id = userid order by time asc limit 2

delete from ut_consign where (select from ut_consign where sale_id = %q order by time desc limit 10 )
...全文
109 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
神的理想 2013-12-12
  • 打赏
  • 举报
回复
引用 1 楼 lzd_83 的回复:
第一条语法是没有错误 修改第二条 delete from ut_consign where sale_id in (select sale_id from ut_consign where sale_id = %q order by time desc limit 10 )
错误 1235 提示 this version of mysql doesn't yet support `limit`&in/all/any/some subquery 我用的是heidi sql 最新的8.1版
Rotel-刘志东 2013-12-12
  • 打赏
  • 举报
回复
第一条语法是没有错误 修改第二条 delete from ut_consign where sale_id in (select sale_id from ut_consign where sale_id = %q order by time desc limit 10 )
rucypli 2013-12-12
  • 打赏
  • 举报
回复
那就把要删的id放到临时表里 create table tmp(id) select from ut_consign where sale_id = %q order by time desc limit 10; delete from ut_consign where sale_id in(slect id from tmp);
wwwwb 2013-12-12
  • 打赏
  • 举报
回复
try: delete a from tt a inner join (select sale_id from tt where sale_id = userid order by time asc limit 2) b on a.sale_id=b.sale_id

56,687

社区成员

发帖
与我相关
我的任务
社区描述
MySQL相关内容讨论专区
社区管理员
  • MySQL
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧