Question

The query I am running is

select accountid from general order by accountid ASC

The result I get is

accountid
------------
1 
1001 
1002
10021 
10026
1006 
1007

Why is it not ordering correctly? It's a simple query and I am completely lost at how I can resolve this matter.

Was it helpful?

Solution

The column type must be a numeric (int, number, bigint, etc) type..

Looks like right now it is a VARCHAR type column... which is sorted like a dictionary...

OTHER TIPS

If SolutionID is the VARCHAR Column and if it has some thing like Sol0, Sol1, Sol2, .... then if you have to sort the column... use the below code

cast (substring(SolutionID,4,10) as integer) desc

Try this, it works:

select accountid from general order by convert(int, accountid) ASC
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top