2016-07-05 9 views
0

Der Versuch, eine benutzerdefinierte Möglichkeit zum Anzeigen von Posts von einer Wordpress-Site zu erstellen. Probleme haben, die genauen Daten zu bekommen, die ich von der Datenbank benötige.SQL-Syntaxfehler in der Nähe von GROUP BY

Das ist also mein Fehler:

Error: 
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 'GROUP BY Imgguid' at line 24 

Und das ist meine Frage:

$sql="SELECT Posts.post_title AS Title, ImgURL.guid AS Imgguid, Posts.guid, Posts.post_content 
FROM `wp_posts` AS Posts 
    INNER JOIN `wp_postmeta` AS Meta ON Posts.ID = Meta.post_id 
    INNER JOIN `wp_postmeta` AS Featured ON Posts.ID = Featured.post_id 
    INNER JOIN `wp_postmeta` AS StartF ON Posts.ID = StartF.post_id 
    INNER JOIN `wp_postmeta` AS EndF ON Posts.ID = EndF.post_id 
    INNER JOIN `wp_postmeta` AS ImgID ON Posts.ID = ImgID.post_id 
    INNER JOIN `wp_posts` AS ImgURL ON ImgID.meta_value = ImgURL.ID 
WHERE 
    (Featured.meta_key = '_ecp_custom_22' AND Featured.meta_value = 'yes') 
    AND 
    (StartF.meta_key = '_ecp_custom_23' AND CAST(StartF.meta_value AS DATETIME) <= CURDATE()) 
    AND 
    (EndF.meta_key = '_ecp_custom_27' AND CAST(EndF.meta_value AS DATETIME) >= CURDATE()) 
    AND 
    (ImgURL.post_type = 'attachment') 
    AND 
    (Posts.ID IN (SELECT relationships.object_id FROM `wp_terms` AS terms 
    INNER JOIN `wp_term_taxonomy` AS taxonomy ON terms.term_id = taxonomy.term_id 
    INNER JOIN `wp_term_relationships` AS relationships ON taxonomy.term_taxonomy_id = relationships.term_taxonomy_id 
    WHERE terms.name = 'Sydney')) 

LIMIT 300 
GROUP BY Title;"; 

nicht sicher, warum es nicht die Gruppe von Bit mag. Vielen Dank.

+0

** ** Grenze letzte by' erste –

+0

'Gruppe kommt dann' limit' –

+0

Dank sortiert jetzt – benikens

Antwort

2

LIMIT 300 Dies sollte am Ende der Abfrage kommen.

GROUP BY Title LIMIT 300 
-2
SELECT Posts.post_title AS Title, ImgURL.guid AS Imgguid, Posts.guid, Posts.post_content 
FROM `wp_posts` AS Posts 
    INNER JOIN `wp_postmeta` AS Meta ON Posts.ID = Meta.post_id 
    INNER JOIN `wp_postmeta` AS Featured ON Posts.ID = Featured.post_id 
    INNER JOIN `wp_postmeta` AS StartF ON Posts.ID = StartF.post_id 
    INNER JOIN `wp_postmeta` AS EndF ON Posts.ID = EndF.post_id 
    INNER JOIN `wp_postmeta` AS ImgID ON Posts.ID = ImgID.post_id 
    INNER JOIN `wp_posts` AS ImgURL ON ImgID.meta_value = ImgURL.ID 
WHERE 
    (Featured.meta_key = '_ecp_custom_22' AND Featured.meta_value = 'yes') 
    AND 
    (StartF.meta_key = '_ecp_custom_23' AND CAST(StartF.meta_value AS DATETIME) <= CURDATE()) 
    AND 
    (EndF.meta_key = '_ecp_custom_27' AND CAST(EndF.meta_value AS DATETIME) >= CURDATE()) 
    AND 
    (ImgURL.post_type = 'attachment') 
    AND 
    (Posts.ID IN (SELECT relationships.object_id FROM `wp_terms` AS terms 
    INNER JOIN `wp_term_taxonomy` AS taxonomy ON terms.term_id = taxonomy.term_id 
    INNER JOIN `wp_term_relationships` AS relationships ON taxonomy.term_taxonomy_id = relationships.term_taxonomy_id 
    WHERE terms.name = 'Sydney')) 
GROUP BY Title 
LIMIT 300 
+1

a, Formatierung. b, das OP hat schon gesagt, dass es sortiert ist. c, dump nicht nur Code erklären es –