1

I have a view that uses a Relationship and Aggregation. My View is working; however, I don't understand how/if I can fix the Query to remove redundant GROUP BY fields. Here's a summary of what I have:

I've created a View with Child items, which have an entity reference field parent_id that I use to create a relationship to Parent items. Each child has four integer quantity fields. Each row should display three text fields from the parent entity and then the SUM of each of the four quantity fields. I use the Aggregation settings on each of the quantity fields to get the SUMs. That works fine. I use "Group results together" for the target_id of the parent_id, which also works fine. What I don't understand is what to do for the other parent entity text fields. It seems that the only option is to use "Group results together" for the aggregation type for each. However, that results in a query with a bunch of extra GROUP BY criteria. I'd like my criteria to look like this:

GROUP BY child_entity_parent_id

instead of this:

GROUP BY child_entity_parent_id, parent_entity_title_field, parent_entity_description_field, parent_entity_size_field 

Is there anything I can do to get those redundant fields out of the group by or do I just ignore them since they're not really hurting anything? Everything else in the query looks good.

(This is Drupal 8, if it matters.)

  • 1
    It really comes down to understanding MySQL sql modes/grouping - once you understand all of that, the way Views makes use of it will be a lot clearer. This article gives a nice intro: blog.gabriela.io/2016/03/03/group-by-are-you-sure-you-know-it – Clive May 17 '17 at 13:32
  • Thank you! Very interesting. I wasn't aware of the newer features of MySQL. Looks like I was used to the "magical" solution working for me. Now all the "extra" fields in the Group By makes sense. – user72086 May 17 '17 at 13:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy