Sort MYSQL varchar column

Salam.

I need to sort a varchar column that contains letter and number. For example

IC
G1000
G9090
G1200
G8900
G18790
G20110

If we just sort by the IC number it will be like this:

IC
G18790
G20110
G1000
G1200
G8900
G9090

I want a result like this:

IC
G1000
G1200
G8900
G9090
G18790
G20110

So what i did, i just combine the function of SUBSTR and also +0

Example : ORDER BY SUBSTR(IC,2)+0 ASC

Where substr function is to read the second letter and +zero is to make it sort faster then use a cast operator.

Bye.

 

This article was written by matn0t.