How do I 'subtract' sql tables?

后端 未结 14 2014
死守一世寂寞
死守一世寂寞 2020-12-05 13:12

Its not really a subtraction I\'m looking for. And I know its not a union or intersection... I have been given a long and complex stored procedure that returns a table of

14条回答
  •  长情又很酷
    2020-12-05 14:18

    You can also do this with the NOT IN clause

    For example, assuming the stored procedures have given you table variables called @AllDocuments and @ActiveDocuments and each document has an identifier column called DocId

    SELECT * FROM @AllDocuments 
    WHERE DocId NOT IN 
        (SELECT DocId FROM @ActiveDocuments)
    

    Adapt this as appropriate to match your table / column names.

提交回复
热议问题