首页
学习
活动
专区
圈层
工具
发布
社区首页 >专栏 >MySQL错误:ERROR 1221 (HY000): Incorrect usage of UNION and ORDER BY

MySQL错误:ERROR 1221 (HY000): Incorrect usage of UNION and ORDER BY

作者头像
恋喵大鲤鱼
发布2018-08-03 14:38:40
发布2018-08-03 14:38:40
1.4K0
举报
文章被收录于专栏:C/C++基础C/C++基础

MySQL版本:Ver 14.14 Distrib 5.1.61, for redhat-linux-gnu (x86_64)

使用union将两个子查询纵向合并后插入到数据表出现了上面的错误,sql语句如下:

代码语言:javascript
复制
insert into lvlvtest1 select * from lvlvtest order by dwMsgTime desc limit 1 union select * from lvlvtest order by dwMsgTime asc limit 1;

将上面的子查询分别加上括号就OK了,无需给子查询加上别名,修改如下:

代码语言:javascript
复制
insert into lvlvtest1 (select * from lvlvtest order by dwMsgTime desc limit 1) union (select * from lvlvtest order by dwMsgTime asc limit 1);

成功!!!

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2016年07月04日,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档