# Group by not working with other column

**URL:** <https://discuss.elastic.co/t/group-by-not-working-with-other-column/207829>\
**Category:** Elasticsearch\
**Created:** [November 14, 2019, 7:51am UTC](https://discuss.elastic.co/t/group-by-not-working-with-other-column/207829 "2019-11-14T07:51:45Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![KrishK](https://avatars.discourse-cdn.com/v4/letter/k/c89c15/32.png) [@KrishK](https://discuss.elastic.co/u/KrishK)\
**Post date:** [November 14, 2019, 7:51am UTC](https://discuss.elastic.co/t/group-by-not-working-with-other-column/207829/1 "2019-11-14T07:51:45Z")

</div>

Hi Support,  
Below query is not working for me.

POST \_sql/format=txt  
{  
"query":"""SELECT count(\*) as matched,col1,col2 FROM index WHERE col0 = 1 group by col1"""  
}

Error :

{  
"error": {  
"root\_cause": [  
{  
"type": "verification\_exception",  
"reason": "Found 1 problem(s)\nline 1:48: Unknown column [col2]"  
}  
],  
"type": "verification\_exception",  
"reason": "Found 1 problem(s)\nline 1:48: Unknown column [col2]"  
},  
"status": 400  
}

Above query is working in SphinxSql and i want use same query and get same result.

Is there any way to get result by using above query?

Can you help me on this issue?

Thanks

---

<div class="post-metadata">

**Author:** ![Andrei\_Stefan](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/andrei_stefan/32/47533_2.png) [@Andrei\_Stefan](https://discuss.elastic.co/u/Andrei_Stefan)\
**Post date:** [November 14, 2019, 11:29pm UTC](https://discuss.elastic.co/t/group-by-not-working-with-other-column/207829/2 "2019-11-14T23:29:40Z")

</div>

@KrishK I think the error message is pretty descriptive: you don't have a column called `col2` in your index named `index`.

Assuming that the column name was just a typo, SELECTing multiple columns and GROUPing BY only one of them is not standard SQL and, as expected, will not work with ES SQL either. You need to have `group by col1, col2`.

---

<div class="post-metadata">

**Author:** ![KrishK](https://avatars.discourse-cdn.com/v4/letter/k/c89c15/32.png) [@KrishK](https://discuss.elastic.co/u/KrishK)\
**Post date:** [November 18, 2019, 5:30am UTC](https://discuss.elastic.co/t/group-by-not-working-with-other-column/207829/3 "2019-11-18T05:30:57Z")

</div>

Thanks

is there any way to select multiple column and grouping by with any single column?

Thanks

---

<div class="post-metadata">

**Author:** ![matriv](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/matriv/32/43656_2.png) [@matriv](https://discuss.elastic.co/u/matriv)\
**Post date:** [November 19, 2019, 1:16pm UTC](https://discuss.elastic.co/t/group-by-not-working-with-other-column/207829/4 "2019-11-19T13:16:41Z")

</div>

No, there isn't. The SELECT list must contain only aggregation functions (COUNT, SUM, AVG, etc.) and columns that are also in the GROUP BY.

---

<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:** [December 17, 2019, 1:16pm UTC](https://discuss.elastic.co/t/group-by-not-working-with-other-column/207829/5 "2019-12-17T13:16:42Z")

</div>

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