首页 > 解决方案 > 使用内部连接的python mysql更新

问题描述

此查询在 中不起作用PyMysql,我似乎找不到问题所在。

query = """UPDATE user INNER JOIN identification_card ON user.id = %s SET user.id_type = %s, user.validity = %s"""
data = (identification_card.user_id, identification_card.card_type, identification_card.expiry_date)
cursor.execute(query,data)

标签: pythonmysqlpymysql

解决方案


为什么要传递列名而不是值

或者您简单地使用连接的列名作为值

  UPDATE user 
  INNER JOIN identification_card ON user.id = identification_card.user_id 
  SET user.id_type = identification_card.card_type 
  user.validity = identification_card.expiry_date 




query = """UPDATE user 
  INNER JOIN identification_card ON user.id = identification_card.user_id 
  SET user.id_type = identification_card.card_type 
  user.validity = identification_card.expiry_date"""

cursor.execute(query,data)

推荐阅读