通过INNER JOIN更新具有来自另一个表的值的Access表

时间:2016-10-11 02:04:05

标签: python sql ms-access pyodbc

我正在尝试使用pyodbc使用来自同一数据库中另一个表中的列的数据来更新列。我试过了:

cursor.execute('''
            UPDATE Prospect_SC_Fin_102016
            SET Prospect_SC_Fin_102016.Sym_Ky=Symbol_Ref_102016.Sym_Ky
            FROM Prospect_SC_Fin_102016
            INNER JOIN Symbol_Ref_102016
            ON Prospect_SC_Fin_102016.Symbol=Symbol_Ref_102016.Symbol;
            ''')
con.commit()
cursor.close()
con.close()

并获得“缺少运算符”语法错误。

我也试过了:

cursor.execute('''
            UPDATE Prospect_SC_Fin_102016
            SET Prospect_SC_Fin_102016.Sym_Ky=(SELECT Sym_Ky
            FROM Symbol_Ref_102016 WHERE Symbol IN
            (SELECT Symbol FROM Prospect_SC_Fin_102016));
            ''')
con.commit()
cursor.close()
con.close()

也出错了。这里的逻辑是什么?

1 个答案:

答案 0 :(得分:2)

对于Access数据库,您可能希望使用以下格式的查询:

UPDATE Prospect_SC_Fin_102016
INNER JOIN Symbol_Ref_102016
    ON Prospect_SC_Fin_102016.Symbol=Symbol_Ref_102016.Symbol
SET Prospect_SC_Fin_102016.Sym_Ky=Symbol_Ref_102016.Sym_Ky