Need SQL Query to find Parent records without child records

前端 未结 6 1726
迷失自我
迷失自我 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

    I simply dont understand whats the having clause doing in your query as I see already you are saying where ChildTable.ChildField_ = '2131' that already means you have record set for childfield 2131 Try the below query it would mean that if the parent doesnt have child in the Childtable with field 2131then o/p the same.

         SELECT    ParentTable.ParentID
             FROM      ParentTable 
             Where ParentTable.ParentID NOT IN (Select ChildID 
            From ChildTable where
             ChildTable.ChildField_ = '2131')
    

提交回复
热议问题