Search code examples
sqlsortingsql-order-byderby

How to sort by INT type column as it would be VARCHAR type column in Derby DB?


Here is the SQL expression:

SELECT * FROM someTable ORDER BY integerTypeColumn ASC;

Column "integerTypeColumn" is INT type. Using Berby DB the results are for example:

1
2
3
1000
1200

But I need to sort like as if the column "integerTypeColumn" would VARCHAR type. Then the results would be:

1
1000
1200
2
3

Is it possible to do it using Derby?


Solution

  • You can cast to char.

    SELECT * FROM someTable 
    ORDER BY CAST (integerTypeColumn AS char(10)) ASC;