联盟不在Mysql中工作

时间:2016-11-09 07:02:56

标签: mysql

我在mysql中编写了UNION代码,但它无效。

请帮忙。

SELECT * FROM (`am_glmaster`) WHERE 
`logid_status` IN ('DISPATCHED','DELIVERED', 'COMPLETE') 
 AND `dispatch_from` =  'New Delhi'
UNION SELECT *
FROM (`glmaster_history`)
WHERE `logid_status` IN ('DISPATCHED', 'DELIVERED', 'COMPLETE') 
AND `glmaster_history`.`dispatch_from` =  'New Delhi'
  

给出错误 - #1064 - 您的SQL语法出错;检查   手册,对应右边的MySQL服务器版本   语法在' WHERE logid_status IN附近使用(' DISPATCHED',   '交付','完成')和'glmaster_h'在第4行

1 个答案:

答案 0 :(得分:1)

试试这个:

SELECT * 
    FROM 
        am_glmaster 
    WHERE 
        logid_status IN ('DISPATCHED','DELIVERED', 'COMPLETE') 
    AND 
        dispatch_from =  'New Delhi'
UNION 
SELECT *
    FROM 
        glmaster_history
    WHERE 
        logid_status IN ('DISPATCHED', 'DELIVERED', 'COMPLETE') 
    AND 
        dispatch_from =  'New Delhi'