【问题标题】:How to not select rows that does not exists in other table如何不选择其他表中不存在的行
【发布时间】:2019-04-25 06:16:23
【问题描述】:

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

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

代码如下

【问题讨论】:

  • 你能告诉我们你尝试了什么吗?
  • 嗨,用我使用的代码更新了我的问题
  • 请粘贴代码,请勿截图!
  • 我似乎无法发布代码,网站显示错误,所以我发布了屏幕截图

标签: sql-server tsql notin


【解决方案1】:

使用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  )

【讨论】:

    猜你喜欢
    • 2013-10-22
    • 1970-01-01
    • 1970-01-01
    • 2019-07-08
    • 2020-06-08
    • 1970-01-01
    • 1970-01-01
    • 2021-01-07
    • 1970-01-01
    相关资源
    最近更新 更多