如何根据另一个表列更新表?

时间:2014-11-29 08:07:28

标签: mysql

如何根据另一个表列更新表?

这是我的SQL。我正在使用MySQL。

UPDATE tb_notify SET alert = '0' WHERE post_id = '01' AND (HERE IS I WANT TO GET BASED ON ANOTHER TABLE)

另一个表是tb_post,每个表中都有相同的参数。那是post_id。

tb_notify
have 3 column:
1. com_id
2. post_id
3. alert

tb_post
have 3 column:
1. post_id
2. uid_post <-- Here I want to based on this column
3. post

请帮忙。 感谢

1 个答案:

答案 0 :(得分:0)

您可以使用联接进行更新

update tb_notify tn
join tb_post tp on tp.post_id = tn.post_id
set
tn.alert = '0'
where
tn.post_id = '01'
AND tp.uid_post = {whatever you want}