读书人

求一条sql语句2表查询解决方法

发布时间: 2012-03-18 13:55:38 作者: rapoo

求一条sql语句,2表查询
我有两张表tab1,tab2,都有一个name字段
要出显示tab1的name字段的结果集,并且结果中不能包含tab2的name字段的值

[解决办法]
select * from tab1 where name not in (select name from tab2)
select * from tab1 where not exists(select 1 from tab2 where name=tab1.name)
[解决办法]
select a.name
from tab1 a
where a.name not in (select name from tab2)

读书人网 >SQL Server

热点推荐