0

i have 2 tables that i want to make them full outer join.

i am using the following query:

select * from permissions 
left join user_news_permission on permissions.userID = user_news_permission.userID
union
select * from permissions 
right join user_news_permission on permissions.userID = user_news_permission.userID

but it makes two userID columns that some are null and some are not.

how can i make it one userID column that all of them are not null?

Matin Lotfaliee
  • 1,745
  • 2
  • 21
  • 43
  • What are you trying to accomplish? The `NULL` user ids are expected, when you use a `full outer join`, so your question doesn't make sense. Sample data and desired results might help. – Gordon Linoff Sep 17 '15 at 12:25

2 Answers2

0

When you do a left join, any records found in the left table but not in the right table will result in all columns in the right table replace by nulls (and vice versa for a right join).

If you are seeing nulls, either a record in the left table exists with a given userID that does not exist in the right table, or a record exists in the right table that does not exist in the left table.

If you are looking for user IDs from permissions and any information from user_news_permission, the former half of the union is sufficient:

select * from permissions 
left join user_news_permission on permissions.userID = user_news_permission.userID

If you are looking for user IDs from user_news_permission and any information from permissions, the latter half of the union is sufficient:

select * from permissions 
right join user_news_permission on permissions.userID = user_news_permission.userID

If you just care about the users in one table, a join isn't necessary. Just select all records from that table.

neverendingqs
  • 4,006
  • 3
  • 29
  • 57
0

I am not a professional But try this

SELECT* FROM permissions
RIGHT JOIN user_news_permission
ON permissions.userID = user_news_permission.userID;
Ali Ather
  • 1
  • 3