2013-07-09 49 views
0

目標是爲一行數據搜索兩個相似的表格。在2個表格中搜索唯一條目,然後更改數據

UPDATE 
regusers_test AS rt 
INNER JOIN 
alt_toon_test AS att 
ON 
att.`toonname` = rt.`toonname` 
SET 
rt.`server` = CASE WHEN rt.`username`='$user' AND rt.`server`='$oserver' AND rt.`toonname`='$otoon' THEN '$server' ELSE rt.`server` 
att.`server` = CASE WHEN att.`username`='$user' AND att.`server`='$oserver' AND att.`toonname`='$otoon' THEN '$server' ELSE att.`server` 
WHERE 
(
rt.`username`='$user' AND rt.`server`='$oserver' AND rt.`toonname`='$otoon' 
) 
OR 
(
att.`username`='$user' AND att.`server`='$oserver' AND att.`toonname`='$otoon' 
) 

但我不斷收到:

You have an error in your SQL syntax; check the manual that corresponds to your mySQL server version for the right syntax to use near 'att.'server'=Case When att.'username'='$user'... 

我做了很多的谷歌搜索在週末,但沒有找到一個解決方案。希望這裏有人知道發生了什麼。

+0

你需要你想設置的兩個字段之間用逗號? – andrewsi

+0

迴應您的查詢。我相信這些錯誤會很明顯。 – Strawberry

回答

0

SET在作業之間需要。

編輯固定查詢:

UPDATE 
regusers_test AS rt 
INNER JOIN 
alt_toon_test AS att 
ON 
att.`toonname` = rt.`toonname` 
SET 
rt.`server` = CASE WHEN rt.`username`='$user' AND rt.`server`='$oserver' AND rt.`toonname`='$otoon' THEN '$server' ELSE rt.`server`, 
att.`server` = CASE WHEN att.`username`='$user' AND att.`server`='$oserver' AND att.`toonname`='$otoon' THEN '$server' ELSE att.`server` 
WHERE 
(
rt.`username`='$user' AND rt.`server`='$oserver' AND rt.`toonname`='$otoon' 
) 
OR 
(
att.`username`='$user' AND att.`server`='$oserver' AND att.`toonname`='$otoon' 
) 
+0

我完全複製並粘貼了Aragon0給我的修復程序,而且我仍然收到相同的消息。 mySQL版本是5.0 – CSharpMinor

+0

DERP,忘記在每列結束處放置「END」case – CSharpMinor

0

你只是錯過了列之間的,附近

SET 
rt.`server` = CASE WHEN rt.`username`='$user' AND rt.`server`='$oserver' AND rt.`toonname`='$otoon' THEN '$server' ELSE rt.`server` END , 
att.`server` = CASE WHEN att.`username`='$user' AND att.`server`='$oserver' AND att.`toonname`='$otoon' THEN '$server' ELSE att.`server` END 
+0

好吧,我添加了逗號,並且仍然出現錯誤。 – CSharpMinor

+0

查看我的更新答案,'CASE'中缺少'END' –

相關問題