Dear Everyone,
First of all, I would like to thank the people that answer questions on this page for the great work you are doing here. I am not very experienced in programming and this page has been a tremendous help for me.
Now coming to my specific question regarding a FULL OUTER JOIN in MySQL. I have two (or more table):
table1 table2 id value id value2 1 a 1 b 2 c 3 d 3 e 4 f
I have used this query to get my join:
SELECT *
FROM table1
LEFT OUTER JOIN table2
ON table1.`id`=table2.`id`
UNION
SELECT *
FROM table1
RIGHT OUTER JOIN table2
ON table1.`id`=table2.`id`
to get:
id value1 id value2 1 a 1 b 2 c NULL NULL 3 e 3 d NULL NULL 4 f
My problem is that I don't manage to simultaneously collapse the two id columns into one column to get this:
id value1 value2 1 a b 2 c NULL 3 e d 4 NULL f
Any suggestions on how to do it?
Use:
The
UNION
operator removes row/record duplicates, so you have to define/list the columns appropriately.Scripts:
Edit: Fixed line above
For what I think you are trying to do, I would suggest using a FULL OUTER JOIN instead: