需要用JOIN替换子查询

时间:2015-07-07 05:04:10

标签: sql oracle performance sql-tuning

我需要在下面使用join而不是Subquery。 任何人都可以帮我用JOIN重写这个。

    update Table1
    set status = 'Edited' 
    where val_74 ='1' and status ='Valid'
    and val_35 is not null
    and (val_35,network_id) in 
    (select val_35,network_id from
    Table2 where val_35 is not null
    and status='Correct_1');



    update Table1 b SET (Val_12,Val_13,Val_14)=
    (select Val_12,Val_13,Val_14 from
      (select Val_35,network_id, Val_12, Val_13, Val_14
      from Table2
      where  Val_34 is not null
      and (REGEXP_LIKE(Val_13,'^[0-9]+$'))
      and (Val_14 is null or (REGEXP_LIKE(Val_14,'^[0-9]+$')))
      group by Val_35,network_id,Val_12,Val_13,Val_14
      )
      where  Val_35 = b.Val_35 and network_id = b.network_id and rownum=1
    )
    where status = 'PCStep2' and (regexp_like(Val_13,'[MSS]+') or regexp_like(Val_14,'[MSS]+'));

我在SQL JOIN中使用了较少的知识,尝试了很多。但得到多个错误。     我们最早可以帮助我查询。

提前衷心感谢

1 个答案:

答案 0 :(得分:0)

实际上,您不能将update语句与join语句混合使用。在update命令之后,update语句始终需要一个表定义。

-- ORA-00971: missing SET keyword
update orders o, customers c
set o.order_value = c.account_value
where o.cust_id = c.cust_id

-- works fine
update orders o
set o.order_value = (select c.account_value  
                     from customers c
                     where c.id = o.cust_id)