2012-12-27 50 views
0

Mysql的UPDATE查詢我想運行此查詢:有兩個表

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'

不過,我得到一個錯誤,因爲我不知道如何在兩個表(UC及以上)相結合更新查詢。

誰能幫我解決這個問題?

感謝,

+0

磨片n您有任何問題,是非常有用的張貼在所治療哪些方面的信息;在這種情況下,它會很高興地看到你的表的結構,看看有什麼可以用來加入他們 – Rubens

回答

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 = '[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' 
+0

我有我的名字列一個錯字,感謝您的幫助,雖然。我會盡我所能接受這個答案。 –

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 = '[email protected]' AND uc.company_id = '4' AND uc.qrcode = 'j' 
+1

感謝您的幫助。 AndreKR擊敗你:) –