无法创建MYSQL视图

时间:2012-11-09 17:02:29

标签: mysql view

首先,我使用的MYSQL版本是5.1.66-community-log

现在我们已经解决了这个问题,我在尝试创建以下视图时检索到以下错误:

  

您的SQL语法有错误;检查手册   对应于您的MySQL服务器版本,以便使用正确的语法   靠近'all select RRA.id,RRA.reply_id as replyID,RRA.user_id,   RRA.vote_up,RRA.rank'在第4行

和视图:

$sql = "Create or replace view userRank as 
select PRA.id, PRA.post_id as postID, PRA.user_id, PRA.vote_up, PRA.rank_date 
from post_rank_activity PRA
union all 
select RRA.id, RRA.reply_id as replyID, RRA.user_id, RRA.vote_up, RRA.rank_date 
from reply_rank_activity RRA";

我检查了一些网站,这似乎是正确的语法 - 或者随着时间的推移有所改变?

4 个答案:

答案 0 :(得分:2)

括号可能会有所帮助,请尝试:

Create or replace view userRank as 
(select PRA.id, PRA.post_id as postID, PRA.user_id, PRA.vote_up, PRA.rank_date 
from post_rank_activity PRA)
union all 
(select RRA.id, RRA.reply_id as replyID, RRA.user_id, RRA.vote_up, RRA.rank_date 
from reply_rank_activity RRA)

答案 1 :(得分:0)

根据this,您的所有不需要,请尝试:

Create or replace view userRank as select PRA.id, PRA.post_id as postID, PRA.user_id, PRA.vote_up, PRA.rank_date from post_rank_activity PRA union select RRA.id, RRA.reply_id as replyID, RRA.user_id, RRA.vote_up, RRA.rank_date from reply_rank_activity RRA;

它应该有效 - 未经测试。

答案 2 :(得分:0)

所有部分中的Union All列在名称和类型上必须相似

这两个是不同的

  • PRA.post_id作为postID

  • RRA.reply_id as replyID

答案 3 :(得分:0)

这似乎是一个甚至在MySQL网站上提出的错误

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