Delete Parent record if child is not present

后端 未结 3 1181
猫巷女王i
猫巷女王i 2021-01-18 15:54

I am creating menu and submenus in a table variable. ( Typical parent child records in the same table) ParentID coll is null for all Top menus. And for their child ParentID

3条回答
  •  执念已碎
    2021-01-18 16:33

    You could do something like this:

    delete from yourtable yt where not exists (select * from yourtable yt2 where yt.id = yt2.parentid) and yt.parentid is null
    

提交回复
热议问题