2013-07-17 46 views
0

我試圖用視圖中的值更新表。目前我使用此代碼:與更新加入視圖的問題

UPDATE member, temp_status_date SET member.status_date = temp_status_date.status_date WHERE member.status_date != temp_status_date.status_date

這phpMyAdmin是給錯誤「#1054 - 未知列‘temp_status_date.status_date’在‘where子句’」 什麼我做錯了什麼?根據官方的MySQL文檔,這不是正確的語法嗎?

回答

0

試試這個:

UPDATE member JOIN temp_status_date ON 
    member.status_date != temp_status_date.status_date 
SET member.status_date = temp_status_date.status_date; 
+0

它仍然返回一個錯誤。我在ON子句中添加了另一個條件,因爲它需要更新正確的成員。 ! 'UPDATE會員註冊temp_status_date ON member.status_date = temp_status_date.status_date AND member.member_id = temp_status_date.member_id SET member.status_date = temp_status_date.status_date' 我得到以下錯誤:「#1054 - 未知列「temp_status_date .status_date'in'子句'「 – linucksrox

+0

我能夠確定問題:我創建的視圖沒有使用列別名,因此名稱實際上是'MAX(member_status_history.status_date)'而不是status_date。 之後的更新工作。謝謝! 'UPDATE構件JOIN temp_status_date ON member.status_date = 'MAX(member_status_history.status_date)' AND member.member_id = temp_status_date.member_id SET member.status_date = 'MAX(member_status_history.status_date)';!' – linucksrox