读书人

简单的SQL语句多主键查询的。

发布时间: 2012-02-20 21:18:23 作者: rapoo

求一个简单的SQL语句,多主键查询的。。
t1表:
ip port
==================
A 1
A 2
B 1
B 2


t2表
ip port
==================
A 1
B 2
A 3
B 4


我要查询t1表中不在t2表中的记录,即要得到t1表中的:
A 2
B 1
这两条记录,请问应该怎么操作?




[解决办法]
select *
from t1
where ip & port not in (select ip & port from t2)

--或

select a.*
from t1 as a
left join t2 as b on a.ip=b.ip and a.port = b.port
where isnull(b.ip) or isnull(b.port)

读书人网 >Access

热点推荐