这是我的SQL Fiddle
这是我的查询:
select employee.eid, staff.acc_no from employee FULL JOIN staff on employee.eid = staff.eid
我可以进行加入,左连接,右连接但不能完全加入。它说错误
Unknown column 'employee.eid' in 'field list': select employee.eid, staff.acc_no from employee FULL JOIN staff on employee.eid = staff.eid
我在做什么错误?
答案 0 :(得分:2)
答案 1 :(得分:1)
MySQL不支持full outer join
。但是,您的表应该具有适当的外键关系,因此不需要:
select employee.eid, staff.acc_no
from employee INNER JOIN
staff
on employee.eid = staff.eid;
如果他们不这样做,您可以使用union all
/ group by
方法:
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;