-1

有两张桌子

Table 1
GroupName     Resolver
Aa                 A
Bb                 B
Cc                 C
Dd                 D

Table 2
key       UserId
1           B
2           C

输出应该是 A 和 D。这意味着 table2 中不存在的记录应该出现。

4

4 回答 4

1
select GroupName,Resolver
from Table1
where Resolver not in (select UserId from Table2)

SQL 小提琴 1

另一个查询

select t1.GroupName,t1.Resolver
from Table1 t1
left join Table2 t2 
on t1.Resolver=t2.UserId
where t2.UserId is null

SQL 小提琴 2

于 2013-06-05T06:58:11.960 回答
1
select * from table1 t1 
left join table2 t2 on t1.Resolver = t2.UserId 
where t2.UserId is null

使用左连接并检查 null

SQLFiddle

于 2013-06-05T06:59:46.177 回答
0

使用以下查询:

Select * from Table1 where Resolver NOT IN (SELECT UserId from Table2);
于 2013-06-05T06:58:30.730 回答
0
select t1.Resolver from Table1 t1, table t2 where t1.Resolver != t2.UserId
于 2013-06-05T07:01:11.983 回答