如何不选择其他表中不存在的行

2021-09-10 00:00:00 tsql sql-server notin

我不想选择其他表中不存在记录的行

I want to not select rows where record does not exists in other table

我希望不会选择 LOCATION 表中不存在但存在于 CYCLE_COUNT_REQUEST 中的 3 行

I expect to not select 3 rows where it does not exists on LOCATION table but exist in CYCLE_COUNT_REQUEST

代码如下

推荐答案

use NOT EXISTS

select *
from CYCLE_COUNT_REQUEST
where not exists (select 1 
                  from LOCATION  )

NOT IN:

 select *
    from CYCLE_COUNT_REQUEST
    where NOT IN(select 1 
                      from LOCATION  )

相关文章