Title: Group by
Last modified: October 3, 2018

---

# Group by

 *  Resolved [Adel](https://wordpress.org/support/users/adells/)
 * (@adells)
 * [7 years, 7 months ago](https://wordpress.org/support/topic/group-by-2/)
 * Hallo Scott,
 * I could really use your help, please.
 * I have a table that contains fields for year, item, a, b, c.
 * The JSON is exported to a url.
 * Each line in the table is exported as an array {}
 * This data needs to be read by another application. In order to do that, I have
   two options, the first of which would be the neatest.
 * To use a simplified example:
 * This is what I get when using SELECT year, item, a, b, c FROM Table.
    {1, QWERTY,
   10, 10, 20} {1, ASDFGH, 15, 15, 30} {2, QWERTY, 5, 5, 8} {2, ASDFGH, 20, 18, 
   17}
 * First prize is to GROUP BY year, with the following expected output:
    [{1, QWERTY,
   10, 10, 20}, {1, ASDFGH, 15, 15, 30}] [{2, QWERTY, 5, 5, 8}, {2, ASDFGH, 20, 
   18, 17}]
 * Obviously the output will be nested, that is not a problem 🙂
 * Is there any way for me to be able to do this?
 * Alternatively, I need to count unique items.
    When I used SELECT year, count_(
   year), a, b, c this example would give me a count of 4. How should I be structuring
   the query to count unique values?
 * Thank you!! 🙂

Viewing 2 replies - 1 through 2 (of 2 total)

 *  Plugin Author [Scott Kingsley Clark](https://wordpress.org/support/users/sc0ttkclark/)
 * (@sc0ttkclark)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/group-by-2/#post-10924201)
 * I don’t think MySQL itself can do this automatically in a regular query, you’d
   have to do some potential sub queries. I can’t offer any additional insights 
   here since I haven’t run across a need for this type of querying before, sorry.
 *  Thread Starter [Adel](https://wordpress.org/support/users/adells/)
 * (@adells)
 * [7 years, 5 months ago](https://wordpress.org/support/topic/group-by-2/#post-10925033)
 * Thanks for the reply, Scott. Appreciate it!

Viewing 2 replies - 1 through 2 (of 2 total)

The topic ‘Group by’ is closed to new replies.

 * ![](https://s.w.org/plugins/geopattern-icon/exports-and-reports.svg)
 * [Exports and Reports](https://wordpress.org/plugins/exports-and-reports/)
 * [Frequently Asked Questions](https://wordpress.org/plugins/exports-and-reports/#faq)
 * [Support Threads](https://wordpress.org/support/plugin/exports-and-reports/)
 * [Active Topics](https://wordpress.org/support/plugin/exports-and-reports/active/)
 * [Unresolved Topics](https://wordpress.org/support/plugin/exports-and-reports/unresolved/)
 * [Reviews](https://wordpress.org/support/plugin/exports-and-reports/reviews/)

 * 2 replies
 * 2 participants
 * Last reply from: [Adel](https://wordpress.org/support/users/adells/)
 * Last activity: [7 years, 5 months ago](https://wordpress.org/support/topic/group-by-2/#post-10925033)
 * Status: resolved