---
title: "How to write Hive queries with column position number in the GROUP BY or ORDER BY clauses"
description: "How to enable column position support in Hive GROUP BY or ORDER BY"
author: "Bartosz Mikulski"
author_bio: "Principal AI Engineer & MLOps Architect. I bridge the gap between \"it works in a notebook\" and \"it works for 200 million users.\""
author_url: https://mikulskibartosz.name
author_linkedin: https://www.linkedin.com/in/mikulskibartosz/
author_github: https://github.com/mikulskibartosz
canonical_url: https://mikulskibartosz.name/column-position-in-hive-groupby-orderby
---

By default, Hive does not support passing the columns to GROUP BY or ORDER BY using their positions instead of names. Therefore, when I try to run this query:

```sql
SELECT column_A, count(*) FROM table_name GROUP BY 1
```

I will see an error message telling me that the `column_A` is not in the GROUP BY expression.

To get the behavior I want, I have to enable the position alias usage before running my query. I can do that by setting the `hive.groupby.orderby.position.alias` property to `true`:

```sql
SET hive.groupby.orderby.position.alias=true;

SELECT column_A, count(*) FROM table_name GROUP BY 1
```

Now, Hive is going to correctly recoginize that I want to group by the first column, lookup its name and use that to execute the query.

