当前位置: 代码迷 >> Sql Server >> 容易 NOT EXISTS
  详细解决方案

容易 NOT EXISTS

热度:414   发布时间:2016-04-24 22:53:10.0
简单 NOT EXISTS
表1)
331501489932 2386202
331501489933 2386176
3394601474L 2417299
3394601474M 2417298
3394601474S 2417297
3394601474XL 2417300
331515369928 2396457
331515369928 2396646
331515369929 2396665
331515369929 2396458
331515369928 2396459
331515369928 2396460
331515369929 2396461
331515369929 2396462
表2)
331515369928 2396457
331515369928 2396646
331515369929 2396665
331515369929 2396458
结果是
表1)里面的
331515369928 2396459
331515369928 2396460
331515369929 2396461
331515369929 2396462
第一列与表2相同,第二列与表2不相同
NOT?EXISTS?

------解决方案--------------------
select * from table1 a
where exists (select 1 from table2 b where b.col1 = a.col1)
and not exists (select 1 from table2 c where c.col1 = a.col1 and c.col2 = a.col2)
  相关解决方案