Reputation: 12467
I want a sort order for a string column like the following (numbers first, letters last):
1
2
...
10
11
...
A
B
C
...
Here's my current query
SELECT * FROM PAGES_VIEW ORDER BY chapterTitle
Unfortunately, this results in the following ordering (10 before 2)
1
10
2
20
...
A
B
...
How do I achieve my desired order?
EDIT: removed my CAST as integer to avoid confusion.
Upvotes: 3
Views: 1408
Reputation: 49260
You should use a case
statement to get the desired order
ing.
select * from pages_view
order by (case when cast(chaptertitle as integer) = chaptertitle then 1
else 0 end) desc, cast(chaptertitle as integer), chaptertitle
Upvotes: 2