0

我正在尝试在 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
4

1 回答 1

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”,我们可以使用连接来构建查询

    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;
于 2012-06-15T07:24:15.553 回答