SELECT
emp.id,
emp.Name,
dept.name
FROM employee as emp
FULL OUTER JOIN department as dept ON emp.dept_id=dept.id
Asked
Active
Viewed 65 times
-2

Mark Miller
- 7,442
- 2
- 16
- 22

Harsh
- 41
- 6
-
You tell us... what is the error? – Mark Miller Jun 06 '14 at 05:46
-
Please add the error message. – Jens Jun 06 '14 at 05:46
-
3possible duplicate of [Full Outer Join in MySQL](http://stackoverflow.com/questions/4796872/full-outer-join-in-mysql) – Jens Jun 06 '14 at 05:51
1 Answers
0
Full outer Joins not Works supports on MYSQL, so Support FULL [OUTER] JOIN by rewriting with UNION. Link
select * from t1 left join t2 on (t1.s1=t2.s1)
union select * from t1 right join t2 on (t1.s1=t2.s1);
or
with two tables t1, t2:
SELECT * FROM t1
LEFT JOIN t2 ON t1.id = t2.id
UNION
SELECT * FROM t1
RIGHT JOIN t2 ON t1.id = t2.id
So the "full join" returns fewer rows than the left join.]
As a full outer join can't be optimized much anyway, the above appears to be a pretty decent solution.
If the joined fields are indexed, we could utilize a method similar to our new "merge index" optimisation to intersect the two indexes and optimize the operation that way.

InventorX
- 423
- 2
- 7