Update小用法一则,在update后面接select表

Oracle:

update inj_wash_updatelog g
 set update_date =
  (select nvl(washdate,subdate) from inj_wash_pro t where  g.proid = t. proid);

MySql

UPDATE tuser a,
    (SELECT 
        t.email, t.cellnum, g.id
    FROM
        tmp_table_user t
    INNER JOIN v_user_group g ON t.name = g.name
        AND (CASE
        WHEN ISNULL(t.team) OR t.team = '' THEN t.room
        ELSE t.team
    END) = g.GNAME
        AND (CASE
        WHEN ISNULL(t.team) OR t.team = '' THEN t.org
        ELSE t.room
    END) = g.pname) b
SET 
    a.email = b.email,
    a.phone = b.cellnum
WHERE
    a.id = b.id



红色部分为重点,update后面接了一个select表,可以以此表中字段做where条件或set语句等号后面的内容

简单来说就是UPDATE后面可以接子查询,虽然前面这句话感觉怪怪的

相关阅读:ORACLE多表关联UPDATE 语句 

http://blog.itpub.net/29378313/viewspace-1064069/

你可能感兴趣的:(Oracle数据库)