我想运行此查询:UPDATE up SET up.pts = uc.checkin_worth WHERE uc.email = up.email AND uc.company_id = up.company_id AND uc.email = '[email protected]' AND uc.company_id = '4' AND uc.qrcode = 'j'
但是,出现错误是因为我不知道如何在UPDATE查询中合并两个表(uc和up)。
谁能帮我解决这个问题?
谢谢,
最佳答案
只需使用普通的JOIN语法即可:
UPDATE up JOIN uc ON uc.email = up.email AND uc.company_id = up.company_id
SET up.pts = uc.checkin_worth
WHERE uc.email = '[email protected]' AND uc.company_id = '4' AND uc.qrcode = 'j'
您还可以使用旧的逗号语法,该语法与原始查询更相似:
UPDATE uc, up
SET up.pts = uc.checkin_worth
WHERE uc.email = up.email
AND uc.company_id = up.company_id
AND uc.email = '[email protected]'
AND uc.company_id = '4'
AND uc.qrcode = 'j'
关于mysql - 带有两个表的MySQL UPDATE查询,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/14048545/