Solved

Query Syntax

Posted on 2016-07-26
5
73 Views
Last Modified: 2016-07-26
I have this query:

 SELECT wp_posts.id, group_concat(wp_postmeta.post_id) as post_id, wp_postmeta.meta_value
 FROM wp_postmeta, wp_posts
 WHERE (wp_postmeta.meta_key = '_VenueState' OR wp_postmeta.meta_key = '_VenueStateProvince') AND wp_posts.post_status = 'publish' 
GROUP BY wp_postmeta.meta_value
ORDER BY wp_postmeta.meta_value ASC

Open in new window


the error I get is this: Expression #1 of SELECT list is not in GROUP BY clause and contains nonaggregated column 'france-am.wp_posts.ID' which is not functionally dependent on columns in GROUP BY clause; this is incompatible with sql_mode=only_full_group_by

Any help I can get to rewrite this so it will run is appreciated.
0
Comment
Question by:lvollmer
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
5 Comments
 

Author Comment

by:lvollmer
ID: 41730377
0
 
LVL 41

Expert Comment

by:Sharath
ID: 41730390
 SELECT wp_posts.id, group_concat(wp_postmeta.post_id) as post_id, wp_postmeta.meta_value
 FROM wp_postmeta, wp_posts
 WHERE (wp_postmeta.meta_key = '_VenueState' OR wp_postmeta.meta_key = '_VenueStateProvince') AND wp_posts.post_status = 'publish' 
GROUP BY wp_posts.id, wp_postmeta.meta_value
ORDER BY wp_postmeta.meta_value ASC

Open in new window

0
 
LVL 41

Accepted Solution

by:
Sharath earned 500 total points
ID: 41730392
Or
 SELECT group_concat(wp_postmeta.post_id) as post_id, wp_postmeta.meta_value
 FROM wp_postmeta, wp_posts
 WHERE (wp_postmeta.meta_key = '_VenueState' OR wp_postmeta.meta_key = '_VenueStateProvince') AND wp_posts.post_status = 'publish' 
GROUP BY wp_postmeta.meta_value
ORDER BY wp_postmeta.meta_value ASC

Open in new window

0
 

Author Closing Comment

by:lvollmer
ID: 41730598
thanks!
0
 
LVL 48

Expert Comment

by:PortletPaul
ID: 41730616
In standard SQL, a query that includes a GROUP BY clause cannot refer to nonaggregated columns in the select list that are not named in the GROUP BY clause.
see: https://dev.mysql.com/doc/refman/5.6/en/group-by-handling.html

As a MySQL users who has (now) experienced this error please be aware that by default MySQL is NON_STANDARD. What has happened is someone has changed the server settings from that default so that the server now requires proper/standard group by queries.

What this means is:

ALL COLUMNS of the select clause need to be repeated in the group by
EXCEPT those using SUM() COUNT() AVG() ... ...  (the aggregation functions)

select col1, col2, col3, col99, sum(abc), count(xyz), avg(gel)
from ...
group by col1, col2, col3, col99

=========================================================
what you should learn to avoid is the default MySQL group by syntax
which would allow this:

select col1, col2, col3, col99, sum(abc), count(xyz), avg(gel)
from ...
group by col1
0

Featured Post

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

I'm trying, I really am. But I've seen so many wrong approaches involving date(time) boundaries I despair about my inability to explain it. I've seen quite a few recently that define a non-leap year as 364 days, or 366 days and the list goes on. …
I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
The purpose of this video is to demonstrate how to integrate Mailchimp with WordPress, by placing a Mailchimp signup form on a WordPress Page or Post. This will be demonstrated using a Windows 8 PC. Mailchimp will be used. Log into your Mailchi…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.

740 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question