2012-05-04 47 views
0

我目前正在PHP中使用MySQL製作公共參考指南。有時垃圾郵件發送者會改變內容,我想恢復到以前版本的頁面。SQL刪除垃圾郵件行,更新最近的行

存儲所有版本的頁面,所以我的問題只是查詢。

UPDATE pages new, pages old SET new.status='2',old.status='1' WHERE new.ip='<spambotip>' AND new.status='0' AND old.title=new.title AND old.status='1' AND old.last_modified IN (SELECT max(last_modified) FROM pages tr WHERE tr.title = new.title AND tr.status='0') 

不過,我得到以下錯誤:

You can't specify target table 'new' for update in FROM clause 

我的查詢是爲了找到狀態= 1(激活),該垃圾郵件機器人制作,設置頁面的2個狀態(垃圾)的所有頁面,然後找到具有最高last_modified,相同標題和狀態0(不活動)並將其狀態設置爲1的頁面。

我認爲我需要使用內部循環,但我遇到了問題,想象它如何能夠做完了。我搜索了一下,但沒有找到任何我可以使用的東西。

任何幫助表示讚賞,謝謝!

+0

一個如何將連接新老版本的同一頁的?他們是否共享相同的ID? –

回答

0

編輯:

Dim sList as String = ... SELECT group_concat(title) FROM pages WHERE ip='<spambotip>' 

UPDATE pages SET staus=2 where title IN (...) 

UPDATE pages SET status=1 where id IN (SELECT id from (SELECT id, max(last_modified) from pages where title in (...) and status=0 group by title) x) 
+0

這也行不通D: #1054 - 編輯爲其他選項的'where子句' –

+0

中的未知列'new.title'。 –