# Ecto query call when using aggregate function

**URL:** <https://forum.elixirforum.com/t/ecto-query-call-when-using-aggregate-function/24900>\
**Category:** Questions\
**Tags:** ecto, phoenix, ecto-query\
**Created:** [August 24, 2019, 10:06pm UTC](https://forum.elixirforum.com/t/ecto-query-call-when-using-aggregate-function/24900 "2019-08-24T22:06:23Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![OvermindDL1](https://forum.elixirforum.com/user_avatar/forum.elixirforum.com/overminddl1/32/2677_2.png) [@OvermindDL1](https://forum.elixirforum.com/u/OvermindDL1)\
**Post date:** [August 26, 2019, 9:34pm UTC](https://forum.elixirforum.com/t/ecto-query-call-when-using-aggregate-function/24900/3 "2019-08-26T21:34:53Z")

</div>

> [@Yama](#):
>
> I was hoping to get a better understanding of why I’m getting this error `t0.id" must appear in the GROUP BY clause or be used in an aggregate function` .

Nothing to do with ecto, that error was coming from your SQL server.

And I’d guess it was because the subquery made no export of `tag_id`, the select only returned `postCount` without any correlation of matching.

Personally I would not have had a subquery, rather just a (left\_)join and group based on the id/name and aggregate (count) the post’s table.

---

_[View the full topic](https://forum.elixirforum.com/t/ecto-query-call-when-using-aggregate-function/24900)._
