2012-09-25 78 views
0

我想運行一個查詢,將刪除除最近9個條目之外的數據庫中的所有條目。 uid是id_lv,表被稱爲last_viewed如何從mysql數據庫刪除舊記錄

mysql_query('DELETE FROM last_viewed WHERE id_lv NOT IN (SELECT id_lv FROM last_viewed ORDER BY id_lv, desc LIMIT 0, 9'); 

我完全沒有錯誤,但沒有任何反應。

感謝

回答

0

包圍錯誤。您錯過了子查詢中的關閉),並且在DESC關鍵字之前不應該有逗號。

mysql_query('DELETE FROM last_viewed 
      WHERE id_lv NOT IN (
       SELECT id_lv 
       FROM last_viewed 
       ORDER BY id_lv desc 
       LIMIT 0, 9)'); 
1
mysql_query('DELETE FROM last_viewed 
       WHERE id_lv NOT IN 
       (SELECT id_lv FROM last_viewed 
       ORDER BY id_lv desc LIMIT 0, 9)'); 
+0

非常感謝 – tatty27