update table1 set price=(select tb2.price from tb2 where tb2.id=table1.id)
where exists(select tb2.price from tb2 where tb2.id=table1.id);

解决方案 »

  1.   

    ORACLE 没有 象SQL SERVER这样的写法吗?
    update t2 set a.price = b.price
    from t2 a,t3  b
    where a.id = b.id那遇到更复杂的更新情况,例如要N个表关联,也是要这样写吗?而且为什么要加where exists(select tb2.price from tb2 where tb2.id=table1.id);呢?
    直接update table1 set price=(select tb2.price from tb2 where tb2.id=table1.id) 有什么问题吗
      

  2.   

    错了,应该是这样的问题:ORACLE 没有 象SQL SERVER这样的写法吗?
    update t2 set price = b.price
    from t2 a,t3  b
    where a.id = b.id那遇到更复杂的更新情况,例如要N个表关联,也是要这样写吗?而且为什么要加where exists(select tb2.price from tb2 where tb2.id=table1.id);呢?
    直接update table1 set price=(select tb2.price from tb2 where tb2.id=table1.id) 有什么问题吗
      

  3.   

    update table1 set price=(select max(tb2.price) from tb2 where tb2.id=table1.id)
    where exists(select 1 from tb2 where tb2.id=table1.id);再试试
      

  4.   

    有的价格相同是对的 但我的条件是 (where tb2.id=table1.id)能不能在想想谢谢了!!!!!
      

  5.   

    update的原理就是一条一条修改数据的,哪有什么一起执行的道理啊
      

  6.   

    楼上这位大哥 你写的语句是用最大的price 代替table1.price ,这样一执行整个数据都成一个max(tb2.price)  我的意思是一一对应
      

  7.   

    如果你table1和table2表里的id字段都是唯一标识的话,那么你执行bzszp(SongZip)的语句的时候是不会出现提示:单行子查询多余一个行!,所以我让你采用max这种写法的
      

  8.   

    我给一张表你看看:
    table1                table2       
    id  price             id   price
    01  1                 01   0 
    02  4                 02   1
    03  4                 03   1
    04  6                 04   2
    就是让table2的代替table1.price     
    帮帮忙
      

  9.   

    SQL> select * from test;ID              PRICE
    ---------- ----------
    01                  1
    02                  4
    03                  4
    04                  6SQL> select * from test1;ID              PRICE
    ---------- ----------
    01                  0
    02                  1
    03                  1
    04                  2SQL> update test set price=(select price from test1 where id=test.id);已更新4行。SQL> select * from test;ID              PRICE
    ---------- ----------
    01                  0
    02                  1
    03                  1
    04                  2SQL>
      

  10.   

    如果不是主键就可能出现多条记录,但我们只要其中的一个,把我们想要的找出来就是了。
    例如,我们要取最大的一个,就可以用max(price)