【问题标题】:SQL Server Query to select only values not in a listSQL Server 查询仅选择不在列表中的值
【发布时间】:2023-01-26 01:13:27
【问题描述】:

例如,我在 SQL Server 中有一个表:

Id
1
3
5

我有一个值列表1,2,3

选择不在表中的列表值的查询是什么。

预期结果 :

Id
2

【问题讨论】:

  • 使用NOT EXISTS
  • 也许select id from table except select id from table where id in (1,2,3)

标签: sql-server sql-server-2012


【解决方案1】:

SELECT * FROM id_table WHERE id NOT IN (1,2,3);

【讨论】:

    猜你喜欢
    • 2017-01-21
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-12-01
    • 1970-01-01
    相关资源
    最近更新 更多