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

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

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

insert into lvlvtest1 select * from lvlvtest order by dwMsgTime desc limit 1 union select * from lvlvtest order by dwMsgTime asc limit 1;

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

insert into lvlvtest1 (select * from lvlvtest order by dwMsgTime desc limit 1) union (select * from lvlvtest order by dwMsgTime asc limit 1);

成功!!!

你可能感兴趣的:(MySQL错误:ERROR 1221 (HY000): Incorrect usage of UNION and ORDER BY)