SQL query to find record with ID not in another table

后端 未结 6 1649
眼角桃花
眼角桃花 2020-12-02 09:02

I have two tables with binding primary key in database and I desire to find a disjoint set between them. For example,

  • Table1 has columns (ID
6条回答
  •  北荒
    北荒 (楼主)
    2020-12-02 09:28

    Try this

    SELECT ID, Name 
    FROM   Table1 
    WHERE  ID NOT IN (SELECT ID FROM Table2)
    

提交回复
热议问题