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

前端 未结 7 1363
小鲜肉
小鲜肉 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.

提交回复
热议问题