Bug #39589 WHERE EXISTS with UNION subquery doesn't work with parentheses.

Submitted: 22 Sep 2008 14:01 Modified: 22 Sep 2008 19:58
Reporter: Jaka Jančar Email Updates:
Status: Duplicate Impact on me:
None 
Category:MySQL Server: Parser Severity:S3 (Non-critical)
Version:5.0.67 OS:Any
Assigned to: CPU Architecture:Any
Tags: exists, subquery, UNION

[22 Sep 2008 14:01] Jaka Jančar
Description:
Hi!

If a subquery within EXISTS uses UNION/UNION ALL and it's "union parts" are wrapped in parentheses, the query is reported as invalid.

How to repeat:
This doesn't work, but I think it should:

mysql> SELECT 1 FROM dual WHERE EXISTS ( (SELECT 1) UNION ALL (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 'UNION ALL (SELECT 2) )' at line 1

But this works:
mysql> SELECT 1 FROM dual WHERE EXISTS ( SELECT 1 UNION ALL SELECT 2 );
+---+
| 1 |
+---+
| 1 | 
+---+
1 row in set (0.00 sec)

On their own both work as expected:
mysql> (SELECT 1) UNION ALL (SELECT 2);
+---+
| 1 |
+---+
| 1 | 
| 2 | 
+---+
2 rows in set (0.05 sec)

mysql> SELECT 1 UNION ALL SELECT 2;
+---+
| 1 |
+---+
| 1 | 
| 2 | 
+---+
2 rows in set (0.00 sec)
[22 Sep 2008 19:58] Sveta Smirnova
Please do not submit the same bug more than once. An existing bug report already describes this very problem. Even if you feel that your issue is somewhat different, the resolution is likely
to be the same. Because of this, we hope you add your comments to the original bug instead.

Thank you for your interest in MySQL.

Duplicate of bug #25734

Portions of this website are copyright © 2001, 2002 The PHP Group

Page generated in 0.049 sec. using MySQL 8.4.7-u6-cloud

Timestamp references displayed by the system are UTC.
Content reproduced on this site is the property of the respective copyright holders.
It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.