如何比较两个MySQL表,然后更新其中一个

时间:2018-02-16 12:49:23

标签: mysql

我有两个名为it_systems和departments的表。 it_systems表包含所有部门名称,但我想添加所有ID,因此我可以删除deprtmentNames列。所以我需要将名称与department表中的名称进行比较,然后将departments.id插入到it_systems.departmentid中,但由于MySQL不是很好,所以看起来似乎正在下降。 这是我有多远

app = Flask(__name__)
@app.route('/',methods=["GET","POST"])
def index():
    #print "came here"
    if request.method == 'POST':
        search_token = request.args.get("validationtoken")
        print "search", search_token
        if search_token != None:
            # text = search_token
            resp = Response(search_token, status=200, mimetype='plain/text')
            print "resp",resp
            return resp
        else:
             print " Notification received "
             ##### HERE I NEED TO CALL THE Java SCRIPT DEFINED IN HTML PAGE TO EXECUTE


    elif request.method=="GET":
         code=request.args.get('code')
         state=request.args.get('state')
         ----

但我一直收到这个错误 [错误] 1054 - 未知专栏&department; department.departmentId'在'字段列表' 即使我知道该栏确实存在。

任何帮助将不胜感激。 提前致谢。 安德烈

1 个答案:

答案 0 :(得分:0)

用户在查询下方实现此目的:

UPDATE it_system_additional AS i
INNER JOIN departments AS d ON i.DepartmentName = d.departmentName
SET i.departmentid = d.departmentId