Reputation: 257
I have the following data:
[sequences]
/a1
/a2
/a3
...
/a10
The query SELECT * FROM sequences WHERE nbr <= '/a10'
should return the list above, instead it returns:
[results]
/a1
/a10
How do I make it return all the rows in the above list?
Upvotes: 7
Views: 27097
Reputation: 36229
SELECT *
FROM sequences
WHERE toInt(substring (nbr, 2)) <= 10;
Name and syntax of 'substring'-function and 'toInt' will vary from db-implementation to db-implementation.
Upvotes: 2
Reputation: 116110
It works as it should. To compare the numeric value, you'll have to convert these to numbers somehow. A good start would be to use substr(yourfieldname, 3) to cut of the
/a. Then you can use
convert` to typecast it to int, so your final query will look something like:
select * from sequences where convert(int, substr(nbr, 3)) <= 10
Mind that the exact functions and rules for converting strings to ints may very per dbms. This illustrates the general idea, though.
Upvotes: 7