Is there a way to create a view from two tables, where one of the columns is different among the two tables? The problem I am currently running into is that MYSQL is telling me that there is an undefined index
- which makes perfect sense since, in half of the cases, the column won't exist.
Table Layout:
(post_rank_activity) ID, post_id, ... date (reply_rank_activity) ID, rank_id, ... date
What I want the resulting view to look like:
ID | Post_id | Reply_id | Date x x NULL x x NULL x x
And the SQL:
$rankView = "Create or replace view userRank as (
select PRA.id, PRA.post_id, PRA.user_id, PRA.vote_up, PRA.rank_date
From post_rank_activity PRA)
union All
(select RRA.id, RRA.reply_id, RRA.user_id, RRA.vote_up, RRA.rank_date
from reply_rank_activity RRA)";
And the result I'm getting, instead of returning null, it's returning the value of "reply_id
" for the "post_id
" field and then shifting all of the other values over - see below:
ID | Post_id | Reply_id | Date x x date val x x reply val date val x
Any ideas?