Skip to content
Advertisement

why does my sql table treat 1000 as a middle number?

When I try to sort by a value descending my SQL table does it correctly, but if it sees for example “1000” it always puts it in the middle? for Example:

enter image description here

this even happens when I reference it in spigot (I’m using it for a plugin) it outputs it the same way

enter image description here

this is how I’m calling it in my plugin:

JavaScript

I know it’s not perfect as I’m just learning/experimenting with databases currently, but I’m mainly asking for help on why the SQL is outputted this way & advice on any severe mistakes I’m making is greatly appreciated! Thanks in advance -Occy

JavaScript

enter image description here

Advertisement

Answer

It happens because block_broken type is a varchar and not a number.

In this case you are ordering lexycographically and not numerically.

You can change your query to handle that as a numeric value with an explicit cast so your query should be:

JavaScript

Update: In MariaDb try to use this (You can try directly in the db client and once it is working update your java code):

JavaScript
Advertisement