从两个单独的SQL表中更新两个条目

时间:2017-04-27 17:42:09

标签: sql join

我正在尝试更新出版物的标题和期刊的年份(对应于它)。我需要做两个单独的查询吗?或者我可以在一个查询中执行此操作吗?

%%sql
    /* Change the title of an article and its publication year. */
    UPDATE publication
    SET title = "Sleepy", year = 2017
    JOIN journal
        ON publication.ID = journal.ID
    WHERE title = "test title";

2 个答案:

答案 0 :(得分:1)

您可以使用此语法更新多个表:

UPDATE table1,table2,... SET column1 = expression1,     column2 = expression2,     ... WHERE table1.column = table2.column [和条件];

答案 1 :(得分:0)

看看这是否有效。令人困惑的是哪些列属于没有架构的哪个表。

UPDATE publication
    SET title = "Sleepy", year = 2017    
    WHERE title = "test title" and ID in (Select ID From journal);