2016-12-26 162 views
0

我想從我的WordPress網站 刪除重複的職位選擇重複的崗位工作currectlly刪除重複的帖子在WordPress

SELECT a.ID, a.post_title, a.post_type, a.post_status 
    FROM wp_posts AS a 
     INNER JOIN (
      SELECT post_title, MIN(id) AS min_id 
      FROM wp_posts 
      WHERE post_type = 'post' 
      AND post_status = 'publish' 
      GROUP BY post_title 
      HAVING COUNT(*) > 1 
     ) AS b ON b.post_title = a.post_title 
    AND b.min_id <> a.id 
    AND a.post_type = 'post' 
    AND a.post_status = 'publish' 

this query that i need has error 
    DELETE a.* 
    FROM wp_posts AS a 
     INNER JOIN (
      SELECT post_title, MIN(id) AS min_id 
      FROM wp_posts 
      WHERE post_type = 'post' 
      AND post_status = 'publish' 
      GROUP BY post_title 
      HAVING COUNT(*) > 1 
     ) AS b ON b.post_title = a.post_title 
    AND b.min_id <> a.id 
    AND a.post_type = 'post' 
    AND a.post_status = 'publish' 

這是錯誤消息:

意外標記(接近a)意外標記(接近。)意外標記 (接近*)

+0

請標記正確使用的RDBMS .....語法可能會有所不同? – Susang

回答

0

第一個SELECT發帖ID。然後使用DELETE聲明與WHERE IN子句。

注意:在執行整個查詢之前,測試IN()子句中的子查詢是否返回正確的ID。

DELETE FROM wp_posts 
WHERE ID IN (
    SELECT a.ID 
    FROM wp_posts AS a 
     INNER JOIN (
      SELECT post_title, MIN(id) AS min_id 
      FROM wp_posts 
      WHERE post_type = 'post' 
      AND post_status = 'publish' 
      GROUP BY post_title 
      HAVING COUNT(*) > 1 
     ) AS b ON b.post_title = a.post_title 
    AND b.min_id <> a.id 
    AND a.post_type = 'post' 
    AND a.post_status = 'publish' 
) 
+0

這個錯誤 MySQL說:文檔 #1064 - 你的SQL語法有錯誤;檢查與您的MySQL服務器版本相對應的手冊,以找到正確的語法,以便在'AS p WHERE p.ID IN( SELECT a.ID FROM wp_posts AS a INNER JOI'in line 1 –

+0

@ m.javadKoushki粘貼在單行的代碼?請現在嘗試 – TRiNE

+0

選擇ID不獲取所有重複posts.its錯誤的查詢 –