T-SQL: Comparing Two Tables - Records that don't exist in second table

前端 未结 7 1309
小鲜肉
小鲜肉 2021-01-02 05:05

If UNION ALL is an addition in T-SQL. What is the equivalent of subtraction?

For example, if I have a table PEOPLE and a table

相关标签:
7条回答
  • 2021-01-02 06:07
    SELECT
         P.*
    FROM
         People P
    LEFT OUTER JOIN Employees E ON
         E.ID = P.ID     -- Or whatever your PK-FK relationship is
    WHERE
         E.ID IS NULL
    

    For SQL Server this will probably be the most performant way that you can do it.

    0 讨论(0)
提交回复
热议问题