对的应该怎么写?我现在只是想按foretak.company_id = foretag_phone.id 的条件,把foretag_phone中的每一条记录的area_code 导到 foretak中。

解决方案 »

  1.   

    id若是字符型:update foretak set area_code=(select area_code  from foretag_phone where id=foretak.company_id and id='100000005');
    若是数定型:
    update foretak set area_code=(select area_code  from foretag_phone where id=foretak.company_id and id=100000005);
      

  2.   

    where后的语句加()
    ...where(,,,,)
      

  3.   

    可否再问一下,如果想按foretak.company_id = foretag_phone.id 的条件,把foretag_phone中的每一条记录的area_code 导到 foretak.area_code中的话,对应的sql豫剧应该怎么写,问题很菜,但是希望可以得到你们的帮助!!!
      

  4.   

    同志,你为什么不好好看 beckham 的回复?update foretak a set area_code = (select area_code from foretag_phone where id = a.company_id)
      

  5.   

    同志,我问问题之前肯定是经过测试的。
    update foretak a set area_code = (select area_code from foretag_phone where id = a.company_id)
    在oracle中根本就没有办法执行,我不知道你试过了没有?包括beckham的写法,也没有办法执行,可能是因为符合查询条件的记录不唯一,比如说:
           foretag_phone.id               foretak.company_id
                  1                                 1
                  2                                 2
                  3                                 3
    虽然ID 和 COMPANY_ID都是唯一的,但是对应的结果并不是唯一的。
    曾经试过这样的更新:
    update foretak a set area_code = (select area_code from foretag_phone where id = a.company_id) WHERE a.company_id = 100000005 就是可以很快执行的,也是因为记录唯一。
    不过,很谢谢你的帮助!!