update 表A 
  set toponym=(select toponym from 表B where 表A.sno=表B.sno),
  haozuo=(select haozuo from 表B where 表A.sno=表B.sno)  
where exists(select 1 from 表B where 表A.sno=表B.sno);

解决方案 »

  1.   

    update 表A 
      set (toponym,haozuo)=(select toponym,hoazyi from 表B where 表A.sno=表B.sno),   
    where exists(select 1 from 表B where 表A.sno=表B.sno);
      

  2.   

    update a set A.TOPONYM=(select b.TOPONYM from b where B.SNO=A.SNO), set a.A.HAOZUO=(select b.HAOZUO from b where b.sno=a.sno)
      

  3.   

    update 表A 
    set A.TOPONYM=(select Max(B.TOPONYM) from 表B where B.SNO=A.SNO),
    A.HAOZUO=(select Max(B.HAOZUO) from 表B where B.SNO=A.SNO)
    where exists(select 1 from 表B where A.sno=B.sno);
      

  4.   

    我将
    update 表A 
      set toponym=(select toponym from 表B where 表A.sno=表B.sno),
          haozuo=(select haozuo from 表B where 表A.sno=表B.sno)  
    where exists(select 1 from 表B where 表A.sno=表B.sno);
    改成了:
    update 表A 
      set toponym=(select toponym from 表B where 表A.sno=表B.sno),
      haozuo=(select haozuo from 表B where 表A.sno=表B.sno)  
    ---------------where exists(select 1 from 表B where 表A.sno=表B.sno)
      WHERE a.sno in (select b.sno where a.sno=b.sno);
    提示"编译成功",但执行起来奇慢无比!五条记录现在已执行了近四分钟了还没完,用EXISTS几秒就搞定了!请问这是怎么回事?
      

  5.   

    这是语句的优化问题,一般的说,exists比in的操作要快。建议多用exists少用in楼主可以找一些关于优化的书看看
      

  6.   

    select b.sno where a.sno=b.sno这一步将取出所有满足条件的b.sno,这一步会消耗很多时间。而用exists时,只要找到一条记录就会停止扫描而返回1