Reputation:
First off, the version of MYSQL I'm using is 5.1.66-community-log
.
Now that we got that out of the way, I'm retrieving the following error when trying to create the below view:
You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'all select RRA.id, RRA.reply_id as replyID, RRA.user_id, RRA.vote_up, RRA.rank' at line 4
and the view:
$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";
I've checked a few sites and this seems to be the correct syntax - or has something changed over time?
Upvotes: 1
Views: 195
Reputation: 775
Parentheses may helps, try :
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)
Upvotes: 2
Reputation: 3585
It seems to be a bug even raised at MySQL Site
http://bugs.mysql.com/bug.php?id=22044
Upvotes: 0
Reputation: 7449
Union All column in all sections have to be similar in name and type
These two are different
PRA.post_id as postID
RRA.reply_id as replyID
Upvotes: 0
Reputation: 34657
According to this, your all is not needed, try:
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;
and it should work -- untested.
Upvotes: 0