MySQL 3.23 UNION fails with Error 1064 [closed]

爱⌒轻易说出口 提交于 2019-12-25 18:35:02

问题


I am trying to use a UNION statement in an old BugZilla MySQL DB running MySQL 3.23. Here is a simplified version of what I am trying to do. It's really nothing exotic but MySQL keeps saying that something is wrong.

(select bug_id,rep_platform from bugs where rep_platform='XX') 
 UNION 
(select bug_id,rep_platform from bugs where rep_platform='YY');

The result I get is:

ERROR 1064 (HY000): You have an error in your SQL syntax near '(select bug_id,rep_platform from bugs where rep_platform='XX')
UNION
(select bu' at line 1

This is really about as simple of a union statement as you can get. Any ideas?

EDIT: I ran a very similar query on a MySQL 5 DB and it worked just fine. Is these some special UNION syntax on MySQL 3 that doesn't show up in documentation or Google searches?


回答1:


The reason why the UNION is not working in MySQL 3 is because MySQL 3 does not support UNION statements :) Take a look at the official documentation.

UNION is used to combine the result from multiple SELECT statements into a single result set. UNION is available from MySQL 4.0.0 on.

Take a look at this article for workarounds.




回答2:


Why not just do this instead:

SELECT DISTINCT bug_id, rep_platform
    FROM bugs
    WHERE rep_platform IN ('XX', 'YY');



回答3:


I think you meant

select bug_id,rep_platform from bugs A where rep_platform='XX'
UNION  
select bug_id,rep_platform from bugs where rep_platform='YY'; 

Joe's answer is much easier and pleasing on the eyes. +1 for Joe.

The two changes I made are

  1. I dropped all parentheses
  2. I put a table alias A next to bugs in the first SELECT


来源:https://stackoverflow.com/questions/9202667/mysql-3-23-union-fails-with-error-1064

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!