# Sorting Categories by Name

**URL:** https://meta.discourse.org/t/sorting-categories-by-name/111430
**Category:** Support
**Created:** [12.Март.2019 22:47:36 UTC](https://meta.discourse.org/t/sorting-categories-by-name/111430 "2019-03-12T22:47:36Z")
**Posts on this page:** 1
**Showing post:** 9

<div class="post-metadata">

### Author: ![csmu](https://sea3.discourse-cdn.com/meta/user_avatar/meta.discourse.org/csmu/32/124581_2.png) [@csmu](https://meta.discourse.org/u/csmu)
#### Post date: [18.Март.2019 21:40:06 UTC](https://meta.discourse.org/t/sorting-categories-by-name/111430/9 "2019-03-18T21:40:06Z")

</div>

I ended up doing this via SQL.

> [@Ordering categories using SQL](https://meta.discourse.org/t/ordering-categories-using-sql/111960):
>
> The following code changes the order of categories to be alphanumeric using SQL. Preconditions. Postgres backend UPDATE categories SET POSITION = subquery.position FROM ( SELECT POSITION , CASE WHEN category\_id = 0 THEN parent\_category\_id ELSE category\_id END category\_id , CASE WHEN category\_id = 0 THEN parent\_category\_name ELSE category\_name END category\_name FROM ( SELECT ROW\_NUMBER - 1 AS POSITION , parent\_category\_id , parent\_category\_name , category\_id , category\_name F…

---

_[View the full topic](https://meta.discourse.org/t/sorting-categories-by-name/111430)._
