I have really big number stored in my db.
They looks like this:
14379999999999997549324988728489489203
25899999999999995535156495356264448
47247499999999996139311253533698818048
6338599999999999164916227526098944
6341299999999999522809053905420288
I store them like this: big_number VARCHAR(100)
How to get lowest number of these values? Number length could be same.
Or should i somehow rebuild my db?
>Solution :
You can compare numbers as strings, that is alphabetically, when they have the same length.
So you’re looking for the shortest number and the first one when sorted alphabetically.
Something like:
SELECT big_number
FROM table_name
ORDER BY LENGTH(big_number), big_number
LIMIT 1.
Here’s a demo: https://www.db-fiddle.com/f/2VowxbkxnhQahaY9WUxDZQ/0