我想在幾列上的兩個表之間使用FULL OUTER JOIN
,但是當兩列都爲空時,在連接期間它們不會被視爲相等,因此我獲得了兩個不同的行。我如何編寫我的連接,所以空列被認爲是平等的?SQL:空列上的全外連接
我已經建立了一個簡單的例子:獲得
create table t1 (
id number(10) NOT NULL,
field1 varchar2(50),
field2 varchar2(50),
CONSTRAINT t1_pk PRIMARY KEY (id)
);
create table t2 (
id number(10) NOT NULL,
field1 varchar2(50),
field2 varchar2(50),
extra_field number(1),
CONSTRAINT t2_pk PRIMARY KEY (id)
);
insert into t1 values(1, 'test', 'test2');
insert into t2 values(1, 'test', 'test2', null);
insert into t1 values(2, 'test1', 'test1');
insert into t2 values(2, 'test1', 'test1', null);
insert into t1 values(3, 'test0', null);
insert into t2 values(3, 'test0', null, 1);
insert into t2 values(4, 'test4', 'test0', 1);
select *
from t1
full outer join t2 using (id, field1, field2);
爲什麼不加入ID列,因爲它們都是各自表的主鍵? – Sentinel