我有2个表,table1 table2
字段有id1,name1,address1 和id2,name2,address21   我想修改table1的数据,update table2 set table2.address2='new' where table1.ud1 = table2.id2
出错,ORA-00904:"table1"."id1":invalid identifier2   我想一起查询两个表 select * from table1,table2 where table1.id1=table2.id2
查询出来的结果没有任何数据,实际上两个表都有数据,而且id1 有等于id2的数据,请问大侠们,我错在哪里呢,

解决方案 »

  1.   

    第一个错误,表关联更新不能这样的,用下面的语句--方法一
    update table2 a
       set address2 = (select address1 from table1 b where a.id2 = b.id1)
     where exists (select address1 from table1 b where a.id2 = b.id1;--方法二
    merge into table2 a
    using table1 b
       on (b.id1 = a.id2)
     when matched then
        update set a.address2  = b.address1;
    第二个问题,你将数据贴出来,你的语句没什么问题,不应该查不出数据。
      

  2.   

    为什么这个帖一分都没有啊..
    第一个
    update table2 a set table2.address2='new' where exists 
      (select 1 from where id1 = a.id2 )
    第二个,语句没错
    你用外连接检查一下select * from table1,table2 where table1.id1=table2.id2(+)
      

  3.   

    第一个问题:
    update table2
    set address2='new'
    where
    id1 in
    (
    select id2 from table1
    )
    第二个问题如楼上所言!