I have a database, that I can not modify, which contains in a table1 in a varchar(255) field1, an 32 bit integer value.
I am interested in the last ten, or such, records of said table from which the integer is smaller than a given parameter value.
Running the next sql statement almost works:
echo 'select field1 from table1 where field1 < 123456 order by field1;'|mysql
The problem is that field1 contains values like
123450
123453
which answer to the selection, but also values like
12344
12345
which also meet the criteria, because of the sort order and method used (sort with string?).
The problem of course is the lack of leading zero's, which I can not help.
What is the best way of solving this in a pure sql query way? Because of time constraints in the final solution, I prefer a single query per parameter.