2013-04-11 50 views
0

我想查詢wordpress數據庫。但是我得到這個錯誤,我無法弄清楚。誰能幫我。WordPress的數據庫的MySQL語法錯誤

查詢:

SELECT DISTINCT aub_terms.* FROM aub_term_relationships 
    JOIN aub_posts ON aub_posts.ID = aub_term_relationships.object_id 
    JOIN aub_term_taxonomy ON aub_term_taxonomy.term_taxonomy_id = aub_term_taxonomy.term_taxonomy_id 
    JOIN ON aub_term_taxonomy.term_id = aub_terms.term_id 
WHERE `aub_term_taxonomy`.`taxonomy` = 'post_tag' 
    AND aub_posts.ID IN (254,239,175,150,119,65,63,61,59,54,51); 

錯誤:

#1064 - 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 'ON aub_term_taxonomy.term_id = aub_terms.term_id WHERE `aub_term_taxonomy`.`taxo' at line 1 
+0

這是什麼........您的查詢是最差的。有很多問題並且不正確。 – 2013-04-11 08:55:46

+0

你可以解釋...'加入aub_term_taxonomy on aub_term_taxonomy.term_taxonomy_id = aub_term_taxonomy.term_taxonomy_id' – 2013-04-11 08:57:47

+0

它的工作現在是。但沒有結果。我從堆棧溢出中得到了這個查詢。但看起來沒用 – 2013-04-11 09:00:55

回答

1

你沒有訪問 「aub_terms」 表的任何地方...... 試試這個:

SELECT DISTINCT aub_terms.* 
FROM aub_term_relationships 
    JOIN aub_posts ON aub_posts.ID = aub_term_relationships.object_id 
    JOIN aub_term_taxonomy ON aub_term_taxonomy.term_taxonomy_id = aub_term_taxonomy.term_taxonomy_id 
    JOIN aub_terms ON aub_term_taxonomy.term_id = aub_terms.term_id 
WHERE `aub_term_taxonomy`.`taxonomy` = 'post_tag' 
AND aub_posts.ID IN (254,239,175,150,119,65,63,61,59,54,51); 
0

你的第三個加盟不包含表名。我想,您的查詢應該如下所示:

SELECT DISTINCT aub_terms.* FROM aub_term_relationships 
JOIN aub_posts ON aub_posts.ID = aub_term_relationships.object_id 
JOIN aub_term_taxonomy ON aub_term_taxonomy.term_taxonomy_id = aub_term_taxonomy.term_taxonomy_id 
JOIN aub_terms ON aub_term_taxonomy.term_id = aub_terms.term_id 
WHERE `aub_term_taxonomy`.`taxonomy` = 'post_tag' 
AND aub_posts.ID IN (254,239,175,150,119,65,63,61,59,54,51);