0

我正在尝试使用 UNION 运算符创建 sql 视图。我尝试先执行 sql,然后再将其嵌入到视图中,结果是成功的。但是当我尝试将其嵌入创建视图时,它返回了此错误

“错误代码:1064 您的 SQL 语法有错误;请查看与您的 MySQL 服务器版本相对应的手册,了解在 'UNION SELECT p.product_media_id AS media_id, p.product_title AS title, p.product' 附近使用的正确语法在第 8 行“

我还保证所有列都具有相同的数据类型。

SQL视图:

CREATE
/*[ALGORITHM = {UNDEFINED | MERGE | TEMPTABLE}]
[DEFINER = { user | CURRENT_USER }]
[SQL SECURITY { DEFINER | INVOKER }]*/
VIEW `mydbname`.`s_views` 
AS
(SELECT c.media_id AS media_id, 
    c.title AS title, 
    c.title_slug AS slug, 
    c.content_one      AS description, 
    c.type AS cat 
FROM content_content c 
WHERE c.type = 'news' 
    OR c.type='travel_genius' 
    AND c.media_id IS NOT NULL 
    AND c.status = 1
UNION
SELECT p.product_media_id AS media_id, 
    p.product_title AS title, 
    p.product_title_slug   AS slug, 
    p.product_description AS description, 
    'product' AS cat 
FROM p_views p
WHERE p.product_media_id IS NOT NULL);
4

1 回答 1

2

这是 MySQL 中的一个错误。触发它的是括号:-

http://bugs.mysql.com/bug.php?id=21614

于 2013-04-03T12:33:21.557 回答