delete from order_detail where order_id in (select order_id from order where cust_id is null) delete from order where cust_id is null
试试这个,你可以先把下面语句中“Delete”部分改为“Select * ”, 看看是不是你想要删除的那些数据,再执行下面的语句以删除它们:Delete From order_Detail Where not exists ( Select * from order a, order_detail b Where a.order_id = b.order_id and a.cust_id not is null)Delete From order Where not exists ( Select * from order a, order_detail b Where a.order_id = b.order_id and a.cust_id not is null)注意,上面的语句也会将两表中 a.order_id <> b.order_id 这类异常数据删除掉!
2.简单的:可以用复合查询,a.order 与b.order_detail来查询。不过如果你不是很熟习逻辑机构的话,还是用第一种比较好一点。
delete from order where cust_id is null
看看是不是你想要删除的那些数据,再执行下面的语句以删除它们:Delete From order_Detail Where not exists (
Select * from order a, order_detail b
Where a.order_id = b.order_id and a.cust_id not is null)Delete From order Where not exists (
Select * from order a, order_detail b
Where a.order_id = b.order_id and a.cust_id not is null)注意,上面的语句也会将两表中 a.order_id <> b.order_id 这类异常数据删除掉!