SQL query to find record with ID not in another table

后端 未结 6 1640
眼角桃花
眼角桃花 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:26

    SELECT COUNT(ID) FROM tblA a
    WHERE a.ID NOT IN (SELECT b.ID FROM tblB b)    --For count
    
    
    SELECT ID FROM tblA a
    WHERE a.ID NOT IN (SELECT b.ID FROM tblB b)    --For results
    

提交回复
热议问题