João Monteiro
João Monteiro

Reputation: 35

Order by with more than 1 of lenght

I'm getting weird results from this query:

SELECT id, nivel, tipo, titulo, texto, ativa 
FROM quests_faq 
ORDER BY nivel ASC;

The result should be like this:

5
10
15
20
40
50
55
etc..

Instead, it is sorting only by the first number:

10
15
2
30
40
5
55
etc

My row "nivel" contains only integers.
How can I use order in this case for the purpose I want?

Upvotes: 0

Views: 31

Answers (2)

ramana_k
ramana_k

Reputation: 1933

This query may do what you are looking for by converting nivel into a number

SELECT id, nivel, tipo, titulo, texto, ativa
FROM quests_faq
ORDER BY CONVERT( nivel, INTEGER) ASC

Upvotes: 1

enriqueojedalara
enriqueojedalara

Reputation: 74

I think this could be helpful:

SELECT id, nivel FROM quests_faq ORDER BY CAST(id as CHAR(13)) ASC

Cheers!

Upvotes: 0

Related Questions