SQL获取失配的行
drop table test_duplicate;
create table test_duplicate(
a int,
b int,
c int
);
create table test_temp(
a int,
b int,
d int
);
insert into test_temp values(1,2,5);
insert into test_temp values(1,2,5);
insert into test_temp values(3,8,5);
insert into test_duplicate values(1,2,3);
insert into test_duplicate values(1,2,3);
insert into test_duplicate values(1,2,5);
insert into test_duplicate values(1,1,1);
insert into test_duplicate values(2,2,3);
insert into test_duplicate values(2,2,5);
select * from test_temp;
select distinct * from test_temp;
select t3.c1, t3.c2, t3.c3 from(
select t1.a as c1, t1.b as c2, t1.d as c3, t2.a as c4, t2.b as c5, t2.c as c6
from test_temp as t1 left join test_duplicate as t2
on (t1.a=t2.a and t1.b=t2.b)
) t3
where t3.c4 is null
;
select * from test_temp as t1
left join test_duplicate as t2
on (t1.a=t2.a and t1.b=t2.b)
where t2.a is null and t2.b is null;
select * from test_temp
where (a,b) in
(
(select a, b from test_temp)
except
(select a, b from test_duplicate)
);
test_duplicate: