Bug #72032 union和order错误
Submitted: 13 Mar 2014 9:38 Modified: 19 Nov 2019 7:55
Reporter: liduo li Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: DML Severity:S5 (Performance)
Version:Server version: 5.0.67-community-nt MySQ, 5.5.38, 5.6.18 OS:Windows (Windows 7 日语版 SP1)
Assigned to: CPU Architecture:Any

[13 Mar 2014 9:38] liduo li
Description:
mysql> select 1 union select 2 order by 1;
+---+
| 1 |
+---+
| 1 |
| 2 |
+---+
2 rows in set (0.06 sec)
mysql>  select 1 union (select 2 order by 1);
+---+
| 1 |
+---+
| 1 |
| 2 |
+---+
2 rows in set (0.00 sec)
mysql>  ( select 1 order by 1 ) union select 2 ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
mysql>

How to repeat:
mysql> select 1 union select 2 order by 1;
+---+
| 1 |
+---+
| 1 |
| 2 |
+---+
2 rows in set (0.06 sec)
mysql>  select 1 union (select 2 order by 1);
+---+
| 1 |
+---+
| 1 |
| 2 |
+---+
2 rows in set (0.00 sec)
mysql>  ( select 1 order by 1 ) union select 2 ;
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '' at line 1
mysql>

Suggested fix:
[13 Mar 2014 11:18] MySQL Verification Team
Hello liduo,

Thank you for the bug report.
Verified as described.

Thanks,
Umesh
[14 Mar 2014 8:08] Hartmut Holzgraefe
ORDER BY isn't needed, just 

  ( select 1 ) union select 2 ;

already fails, too
[19 Nov 2019 7:10] Gleb Shchepa
Has fixed in 5.7.
[19 Nov 2019 7:55] Gleb Shchepa
Thank you for your bug report. This issue has already been fixed in the latest released version of that product, which you can download at

  http://www.mysql.com/downloads/