gpt4 book ai didi

具有两个表的Mysql UPDATE查询

转载 作者:太空宇宙 更新时间:2023-11-03 12:34:07 25 4
gpt4 key购买 nike

我想运行这个查询:

UPDATE up SET up.pts = uc.checkin_worth WHERE uc.email = up.email AND uc.company_id = up.company_id AND uc.email = 'test@gmail.com' 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 = 'test@gmail.com' 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 = 'test@gmail.com'
AND uc.company_id = '4'
AND uc.qrcode = 'j'

关于具有两个表的Mysql UPDATE查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14048545/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com