Ecto query call when using 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.