我正在尝试在oracle中执行以下查询但不能在此处形成它user_id = 561 in x1_table
。查询看起来像
delete from x1_table where id in (select id from y1_table where actual_id=123 )
and user_id of x1_table should not be a part of select owner_id from y1_table
答案 0 :(得分:0)
delete x from x1_table x
where x.user_id = 123 and
x.id in (select id from y1_table where actual_id = 123 ) and
x.user_id not in ( select owner_id from y1_table );
由于我们在两个表中都有列'id',所以我们可以使用join
进行查询 delete x from x1_table x join y1_table y
on x.id = y.id
where x.user_id = 789 and
y.actual_id = 123 and
x.user_id != y.owner_id;