# Cannot order by non-grouped column\[column name\]

**URL:** <https://discuss.elastic.co/t/cannot-order-by-non-grouped-column-column-name/302675>\
**Category:** Elasticsearch\
**Created:** [April 19, 2022, 7:20am UTC](https://discuss.elastic.co/t/cannot-order-by-non-grouped-column-column-name/302675 "2022-04-19T07:20:05Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![dido](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dido/32/104521_2.png) [@dido](https://discuss.elastic.co/u/dido)\
**Post date:** [April 19, 2022, 7:20am UTC](https://discuss.elastic.co/t/cannot-order-by-non-grouped-column-column-name/302675/1 "2022-04-19T07:20:05Z")

</div>

![image](https://us1.discourse-cdn.com/elastic/original/3X/f/a/fa1d8438d973d4ad7cce7e4394a3f33417269385.png)

`select * from (select street, count(street) as counts, min(grocery) as grocery, min(school) as school, (min(grocery) + min(school)) as score from geo_address group by 1) t order by grocery`

I have geo\_address index and I am creating column on the fly which is score that is sum of grocery column and school column.

Now it is sorted based on the grocery but I want to sort based on score. when I try to sort by it I get an error : - Cannot order by non-grouped column [score]. I asked this on Elasticsearch github issue page and I got response that this documented limitation of Elasticsearch here =\> [Cannot order by non-grouped column[column name] · Issue #85894 · elastic/elasticsearch · GitHub](https://github.com/elastic/elasticsearch/issues/85894#issuecomment-1099531925)  
Is there other way around to work with this issue? How can write normal elastic query to achieve this? any help would be appreciated.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [May 17, 2022, 7:20am UTC](https://discuss.elastic.co/t/cannot-order-by-non-grouped-column-column-name/302675/2 "2022-05-17T07:20:46Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
