0

我有 3 个表,说RELATIONS,PERSON,COMPANY 我需要通过加入这 3 个表来UPDATE active_flag字段。我的要求是PERSON'I'/'A'

UPDATE PERSON p
SET p.active_flag ='I'
FROM PERSON p,RELATIONS r,COMPANY c
WHERE p.email ='email@gmail.com'
AND c.rel_id = r.id
AND r.dep_id = '1234567'
AND r.book_id = '1234567'

我怎样才能做到这一点??

4

2 回答 2

1

--不确定连接

UPDATE p
SET 
    p.[active_flag] ='I'
FROM Person p
    INNER JOIN Relations r ON
        r.[vNumber] = p.[vesionNo]
    INNER JOIN Company c ON
        c.[rel_id] = r.[id]
WHERE
    p.[email] ='email@gmail.com'
AND r.[dep_id] = '1234567' 
AND r.[book_id] = '1234567'
于 2012-08-16T09:23:29.163 回答
1
merge into person p
using (
       select id
       FROM PERSON p,RELATIONS r,COMPANY c
       WHERE p.email ='email@gmail.com'
             AND c.rel_id = r.id
             AND r.dep_id = '1234567'
             AND r.book_id = '1234567'
      ) pu
on (pu.id = p.id)
when matched then update set p.active_flag ='I'
于 2012-08-16T11:31:07.793 回答