我正在尝试使用 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);