访问SQL完全外部联接

时间:2018-03-02 18:40:32

标签: sql ms-access

您好我正在尝试通过Full Outer连接两个表来访问,因为我想保留所有项目。

这是我的代码:

    SELECT aa.*, bb.firstname, bb.lastname, bb.totalcost
    FROM (select IT.*,HR.*from IT
    left join HR on HR.firstname=it.firstname and HR.lastname=IT.lastname)  
    AS 
    aa FULL OUTER JOIN 2016totalcost AS bb ON (bb.lastname=aa.IT.lastname) 
    AND (bb.firstname=aa.IT.firstname);

但是我从from子句

中得到了错误语法错误

感谢您的帮助

3 个答案:

答案 0 :(得分:0)

注意:当我回答时,问题标记为Oracle。

Oracle语法为:

select IT.*, HR.*, bb.firstname, bb.lastname, bb.totalcost
from IT left join
     HR
     on HR.firstname = it.firstname and HR.lastname = IT.lastname full outer join 
     2016totalcost tc 
     on tc.lastname = it.lastname and tc.firstname = it.firstname;

答案 1 :(得分:0)

Access无法识别完全外部加入。

以下是如何编写MSA等效项的示例。

How do I write a full outer join query in access

答案 2 :(得分:0)

进行LEFT JOIN并将其联合起来加入:

SELECT 
    *
FROM 
    Table1
LEFT JOIN 
    Table 2
ON 
    Table1.joincolumn = Table2.joincolumn
UNION
SELECT 
    *
FROM 
    Table1
RIGHT JOIN 
    Table 2
ON 
    Table1.joincolumn = Table2.joincolumn