EKsumic's Blog

let today = new Beginning();

Click the left button to use the catalog.

Sort By :
Default
UpdateTime
Reads
RSS  RSS

原創 关于在MySQL删除评论区丢失父Id的评论数据(垃圾数据)

​ 查询是否存在父Id和该表其他Id一致的数据: SELECT * FROM Comments A WHERE EXISTS(SELECT * FROM Comments B WHERE A.`ParentId`=B.`Id`) 这一条可以查询出来到底还要多少条合法子数据。 非法子数据直接加NOT会把父Id=0也筛选出来: SELECT * FROM Comments A WHERE NOT EXISTS(SELECT * FROM Comments B WHERE A.`ParentId`=B.`Id` ) 所以应该再加一句AND ParentId!=0: SELECT * FROM Comments A WHERE NOT EXISTS(SELECT * FROM Comments B WHERE A.`ParentId`=B.`Id`) AND ParentId!=0 但是最后删除的话,用这句其实是不行 ...

2022-03-04 13:04:47

1k+ 1580 reads

1 comments