Need SQL Query to find Parent records without child records

前端 未结 6 1696
迷失自我
迷失自我 2020-12-08 10:12

I am not at all conversant in SQL so was hoping someone could help me with a query that will find all the records in a parent table for which there are no records in a child

6条回答
  •  野趣味
    野趣味 (楼主)
    2020-12-08 10:49

    If you do a left join on the child table and simply say where the child parentID is null.

    SELECT ParentTable.ParentID FROM ParentTable P
        Left Join ChildTable C on C.ParentID = P.ParentID
        WHERE C.Id IS NULL;
    

提交回复
热议问题