PG::UndefinedColumn: ERROR: column "count_articles" does not exist LINE 1: ...08-22 08:44:24.442102') GROUP BY tags.id ORDER BY count_arti... ^ : SELECT COUNT(*) AS count_all, tags.id AS tags_id FROM "tags" INNER JOIN "article_tags" ON "article_tags"."tag_id" = "tags"."id" INNER JOIN "articles" ON "articles"."id" = "article_tags"."article_id" WHERE "tags"."site_id" = $1 AND (articles.enabled = 1) AND (articles.published_at <= '2018-11-22 08:44:24.442035') AND (articles.published_at > '2018-08-22 08:44:24.442102') GROUP BY tags.id ORDER BY count_articles desc, name asc LIMIT $2