SQL根据另一个表中的条件更新一个表

| 两张桌子。
Content (table),
   topic_id (primary key),
   data (text)

Topics (table),
   topic_id (primary key),
   content_type (text)
两个表具有相同的主键数据(topic_id)。 我需要使用文本\“ disabled \”更新数据字段(内容表),但仅在content_type字段(主题表)=文本\“ rvf \”的情况下 我可以:
SELECT * from topics WHERE content_type = \"rvf\";
我可以:
UPDATE content SET data = (\"disabled\");
但是我怎么把它们放在一起。     
已邀请:
标准ANSI SQL解决方案(应在任何DBMS上运行)
UPDATE content 
   SET data = \'disabled\'
 WHERE topic_id IN (SELECT t.topic_id 
                    FROM topics t
                    WHERE t.content_type = \'rvf\')
    
如果您使用的是SQL Server,这应该可以工作
UPDATE content 
SET data = \'disabled\'
FROM content
INNER JOIN topics
on content.topic_id = topics.topic_id
WHERE content_type = \'rvf\'
您还可以执行以下操作,使用主题中的值更新内容:
UPDATE content 
SET content.data = topics.content_type
FROM content
INNER JOIN topics
on content.topic_id = topics.topic_id
WHERE content_type = \'rvf\'
不确定是否在这种情况下适用,但是很高兴知道您可以...     

要回复问题请先登录注册