这个mysql查询可以独立运行。但是当我使用此查询创建视图时,sql yog中会出现Error Code: 1064
消息。请确定此错误的原因。
CREATE
VIEW `databaseName`.`viewName`
AS
((SELECT
`tblgrn`.`InitialLabNo`
, `invlabtes`.`Code` AS LabNo
, `invlabmaterial`.`Description` AS material
, `invlabtessubtable`.`SrNo`
, `invlabtessubtable`.`Result`
,COALESCE(NULL, 'Verified') AS TYPE
, `tblgrn`.`Comp_Code`
, `tblgrn`.`Unit_Code`
, `tblgrn`.`UserId`
FROM
`tblgrn`
INNER JOIN `invlabtes`
ON (`tblgrn`.`InitialLabNo` = `invlabtes`.`Code`)
INNER JOIN `invlabtessubtable`
ON (`invlabtes`.`Code` = `invlabtessubtable`.`Code`)
INNER JOIN `invlabmaterial`
ON (`invlabtessubtable`.`TestCode` = `invlabmaterial`.`Code`))
UNION
(SELECT
`tblgrn`.`InitialLabNo`
, `invlabtesscale`.`Code` AS LabNo
, `invlabmaterial`.`Description`
, `invlabscalesubtable`.`SrNo`
, `invlabscalesubtable`.`Result`
,COALESCE(NULL, 'Running') AS TYPE
, `tblgrn`.`Comp_Code`
, `tblgrn`.`Unit_Code`
, `tblgrn`.`UserId`
FROM
`tblgrn`
INNER JOIN `invlabtesscale`
ON (`tblgrn`.`InitialLabNo` = `invlabtesscale`.`IniLabNo`)
INNER JOIN `invlabscalesubtable`
ON (`invlabtesscale`.`Code` = `invlabscalesubtable`.`Code`)
INNER JOIN `invlabmaterial`
ON (`invlabscalesubtable`.`TestCode` = `invlabmaterial`.`Code`)));
这是错误消息:
错误代码:1064
您的SQL语法有错误;检查与MySQL服务器版本对应的手册,以便在UNION附近使用正确的语法
选择
tblgrn
。InitialLabNo
,invlabtesscale
。Code
AS LabNo'在第22行
执行时间:0秒 转移时间:0秒 总时间:0.018秒
答案 0 :(得分:0)
删除UNION和SELECT之间的括号。
UNION
(SELECT
应该是
UNION
SELECT
您可能还需要移除右括号。