BlogProgramming

MySQL: How to order VARCHAR as INT

Sometimes it is needed to order type fields VARCHAR as INT. If you order a VARCHAR type field, the result can look like this:

1
2
3
4
5
6
7
8
9
10
1
10
2a
2b
2c
3a
3b
340
4
5

but, really, what you wanted is something like this:

1
2
3
4
5
6
7
8
9
10
1
2a
2b
2c
3a
3b
4
5
10
340

Follow this example:

1
2
3
ORDER BY
(core_gmoulds_obras_ctrl_dim_pecas.referencia+0) ASC,
core_gmoulds_obras_ctrl_dim_pecas.referencia ASC

Did it work for you? Please let me know in the comments below.

Artigos Relacionados

Deixe um comentário

O seu endereço de email não será publicado. Campos obrigatórios marcados com *

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Botão Voltar ao Topo
João Clérigo - Photography
Fechar

AdBlocker Detetado
AdBlocker Detected

Por favor ajude este website permitindo a visualização de alguns anúncios. Obrigado. Please help this website allowing the view of some advertising. Thank you!