[英]SQL syntax error near GROUP BY
Trying to create a custom way of displaying posts from a wordpress site. 尝试创建一种自定义方式来显示来自wordpress网站的帖子。 Having issues getting the exact data I need from the database.
从数据库获取我需要的确切数据时遇到问题。
So this is my error: 所以这是我的错误:
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
And this is my query: 这是我的查询:
$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;";
Not sure why it doesn't like the Group By bit. 不知道为什么不喜欢Group By。 Thanks.
谢谢。
LIMIT 300
这应该在查询的末尾。
GROUP BY Title LIMIT 300
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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.