1
I have a table with a varchar column and I want to perform a SELECT and sort the result by the numbers in that column.
The table:
name: coins columns: id, name, price, catalog
The catalogue column consists of a VARHCAR(50), for example, having the following values: currency 1 - 'CJ 0039'; Currency 2 - 'CJ 0025'; currency 3 - 'CJ 0131.2'; Currency 4 - 'CJ 0206';
I want to order the result like this: currency 2; currency 1; currency 3; coin 4;
I’ve tried the following select:
SELECT
id,
catalogo,
preco FROM moedas
order by ABS(CAST(catalogo AS UNSIGNED)) asc
You could show the creation script of your table and select that you have tried?
– Luis Alberto Batista
SELECT id, catalogue, price FROM coins order by ABS(CAST(catalogue AS UNSIGNED)) asc
– Developer1903
If you want to order only by numerical part ?
– Motta
This, by the numeric part present in the column catalog
– Developer1903