1

Here is my SQL Fiddle

And here is my Query :

select employee.eid, staff.acc_no from employee FULL JOIN staff on employee.eid = staff.eid

I can able to do join, left join, right join but not full join. It says the error

Unknown column 'employee.eid' in 'field list': select employee.eid, staff.acc_no from employee FULL JOIN staff on employee.eid = staff.eid

What is the mistake i am doing ??

SA__
  • 1,782
  • 3
  • 20
  • 41

2 Answers2

2

As @Niels pointed out firstly you dont have full joins in mysql.

I would recommend you to read this.

However you can emulate outer join with the help of a UNION operator.

The detailed explanation could be found here as well

Community
  • 1
  • 1
Avinash Babu
  • 6,171
  • 3
  • 21
  • 26
1

MySQL does not support full outer join. However, your tables should have proper foreign key relationships, so it should not be necessary:

select employee.eid, staff.acc_no
from employee INNER JOIN
     staff
     on employee.eid = staff.eid;

If they don't, you can use the union all/group by approach:

select eid, max(accno) as accno
from (select e.eid, NULL as acc_no from employee e union all
      select s.eid, s.acc_no from staff
     ) se
group by eid;
Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786