0

我想运行这个查询:

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)。

谁能帮我解决这个问题?

谢谢,

4

2 回答 2

2

只需使用正常的 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'
于 2012-12-27T02:09:53.700 回答
1

试试这个:

UPDATE up, uc 
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'
于 2012-12-27T02:10:12.603 回答