如何使用2个表中的连接执行不等于函数

时间:2014-07-21 12:58:51

标签: sql sql-server join

我有两个表usr和mat,这里我正在尝试编写一个查询,其中mat假设给我结果(UID!= DID)只有来自mat表的不等值 即,(6,'q','r'),(7,'s','t')仅使用不存在,不存在或IN的连接

create table usr ( uid int, uco varchar, umo varchar);

insert into usr (uid,uco,umo) values (1,'k','l'), (2,'m','n'), (3,'o','p'), (6,'q','r'), (7,'s','t');

create table mat( did int, co varchar, mo varchar);

insert into mat (did,co,mo) values (1,'a','f'), (2,'b','g'), (3,'c','h'), (4,'d','i'), (5,'e','j');

1 个答案:

答案 0 :(得分:5)

这可能是你正在看的 -

select * from usr left outer join mat on usr.uid = mat.did where did is null