[英]how to write an update based on the values of other tables
我想更新1個表,但是使用基於其他表的值的條件。 因此共有三張桌子。
例如
表:電子郵件
pid | email_addr | code | status | preferred_ind
--------------------------------------------------
0 ex@some.com HOME A Y
1 ex2@new.com MB A Y
2 ex3@new.com HOME I N
表:人
pid | id | change_ind |
-----------------------
0 53 NULL
1 54 NULL
2 55 Y
表:溫度
id | email_addr
---------------
53 replace1@new.com
54 replace2@new.com
55 replace3@new.com
我想要
UPDATE email
SET
status = 'I'
preferred_ind = 'N'
WHERE
email_pid=person_pid and
person_id = temp_id and
person_change_ind is NULL and
email_status_ind = 'A' and
email_email_addr != temp_email_addr
您可以進行子查詢
update Email
set status = 'I',
preferred_ind = 'N'
where Email.pid in (select E.pid
from Email E
inner join Person P on P.pid = E.pid
inner join Temp T on T.id = P.pid
where P.change_ind is null
and E.status = 'A'
and E.email_addr <> T.email_addr);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.