2012-10-03 224 views
0
更新

我想執行類似的東西:MySQL中,從選擇結果

   UPDATE page_results 
      SET cache_valid=0 
      WHERE link_id IN (SELECT DISTINCT l.link_id 
      FROM link_results AS l 
      INNER JOIN page_results AS p ON p.link_id=p.link_id 
      WHERE has_no_robots=0 AND cache_valid=1 AND cache_to_expire=1 AND status_code!='404' AND href!='' AND anchor_match!='' AND nofollow=0) 

基本上,我想更新所有的結果,這是派生表採取..

其他解決辦法,我已經是這樣的:

   UPDATE (SELECT DISTINCT l.link_id 
      FROM link_results AS l 
      INNER JOIN page_results AS p ON p.link_id=p.link_id 
      WHERE has_no_robots=0 AND cache_valid=1 AND cache_to_expire=1 AND status_code!='404' AND href!='' AND anchor_match!='' AND nofollow=0) 
      SET cache_valid=0 

但沒有工作或者..有辦法acheive我的目標是什麼?

+0

什麼是你在第一次收到錯誤例如? – Cosmin

回答

1

這裏是這樣做的正確的語法:

UPDATE page_results t1 
INNER JOIN link_results AS l ON t1.link_id = l.link_id 
SET t1.cache_valid = 0 
WHERE t1.has_no_robots = 0 
    AND t1.cache_valid  = 1 
    AND t1.cache_to_expire = 1 
    AND t1.status_code != '404' 
    AND t1.href!   = '' 
    AND t1.anchor_match != '' 
    AND t1.nofollow  = 0; 
0

這是因爲在連接子句錯誤條件p.link_id=p.link_id,嘗試此查詢:

UPDATE page_results p 
     INNER JOIN link_results l 
      ON p.link_id = l.link_id 
    SET p.cache_valid = 0 
    WHERE has_no_robots = 0 AND 
     cache_valid = 1 AND 
     cache_to_expire = 1 AND 
     status_code != '404' AND 
     href != '' AND 
     anchor_match != '' AND 
     nofollow = 0;