日期:2014-05-16  浏览次数:21006 次

求一个简单的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)