首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 数据库 > Access >

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

2012-02-20 
求一个简单的SQL语句,多主键查询的。。t1表:ipportA1A2B1B2t2表ipport

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

热点排行