全连接FULL JOIN-two side outer join

[@more@]

FULL JOIN -two side outer join

Syntax

FROM Table1 [Alias1] FULL JOIN Table2 [Alias2] ON {Table1|Alias1}.Field1 = {Table2|Alias2}.Field2
SQL92 (explicit declaration of a full or union join)

SELECT Fieldlist FROM Table1 [Alias1] LEFT JOIN Table2 [Alias2] ON {Table1|Alias1}.Field1 = {Table2|Alias2}.Field2 UNION
SELECT Fieldlist FROM Table1 [Alias1] RIGHT JOIN Table2 [Alias2] ON {Table1|Alias1}.Field1 = {Table2|Alias2}.Field2
SQL92 (if a direct declaration of a full or union join is not supported by the database system)

SELECT Fieldlist FROM Table1 [Alias1], OUTER Table2 [Alias2]
WHERE {Table1|Alias1}.Field1 = {Table2|Alias2}.Field2 UNION
SELECT Fieldlist FROM OUTER Table1 [Alias1], Table2 [Alias2]
WHERE {Table1|Alias1}.Field1 = {Table2|Alias2}.Field2
Informix before SQL92 (implicit join declaration)

SELECT Fieldlist FROM Table1 [Alias1], Table2 [Alias2]
WHERE ({Table1|Alias1}.Field1 = {Table2|Alias2}.Field2(+)) UNION
SELECT Fieldlist FROM Table1 [Alias1], Table2 [Alias2]
WHERE ({Table1|Alias1}.Field1(+) = {Table2|Alias2}.Field2)
Oracle before SQL92 (implicit join declaration)

Description

The full or the full outer join includes all records from both tables in one resulting row, where the specifyed join expression evaluates as true. Additionally all records from the left table, where is no match in the right table, and all records from the right table, where is no match in the left table, are included in the query results.

Attention, if the database system does not directly support a full join (Syntax 1), all matching records in both tables are selected in the first select statement with the left join and then are selected a second time in the second select statement with the right join. At the and duplicate rows are eliminated with UNION (without ALL, this is importand).

在SAP出来的数据中,用户名的中文名和英文名是用2行分别存储;

USER ID NAME TYPE NAME

---------------------------------------------------------

1 En John

1 Cn 约翰

2 En Ken

2 Cn 肯

3 En davin

4 Cn 纳什

先要把该用户信息ETL到目标表中,目标表的结构成

USER ID EN_NAME CN_NAME

-----------------------------------------------------------

1 John 约翰

2 Ken 肯

3 davin

4 纳什

目前要用一条SQL实现ETL过程:

insert into target_table(user_id,en_name,cn_name)

(

select user_id,en_name,cn_name from

(

select user_id,en_name from src_table where name_type='En' a full join select user_id,cn_name from src_table where name_type='Cn' b on a.user_id=b.user_id

)

)

来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/15086/viewspace-909274/,如需转载,请注明出处,否则将追究法律责任。

转载于:http://blog.itpub.net/15086/viewspace-909274/

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值