Questions tagged [natural-sort]

Natural sorting is ordering values the way a human would. For example, "a2" comes before "a10" while a simple minded character-by-character comparison would put "a10" before "a2". Especially useful for IP addresses or version numbers.

Filter by
Sorted by
Tagged with
15 votes
4 answers

Is there a collation to sort the following strings in the following order 1,2,3,6,10,10A,10B,11?

I have a database with a VARCHAR column that contains integers of varying length. I want to sort them so 10 comes after 9, not 1, and 70A comes after 70. I was able do this with PATINDEX(), a CTE, and ...
Justin Dearing's user avatar
9 votes
2 answers

Why does Postgres ORDER BY seem to halfway ignore leading underscores?

I have an animal table with a name varchar(255), and I've added rows with the following values: Piranha __Starts With 2 Rhino Starts With 1 0_Zebra _Starts With 1 Antelope _Starts With 1 When I run ...
orokusaki's user avatar
  • 1,119
7 votes
1 answer

Order by alphabet and then by numbers

I have records like A5 A4 Z1 B2 C7 C1A C11A B1 B4 I want them to be sorted in this manner A4 A5 B1 B2 B4 C1 C11A C7 Z1 using the ORDER BY clause. I want them to be sorted by alphabets ...
Abhishek's user avatar
  • 145