I am sorting a multi-table join on sort columns from each but it is sorting the numeric columns as if they are alpha columns, i.e. 11 sorts before 2. How do I get around this and why does it do it in the first place?
If 11 is ordered before 2 then the expression in your order by clause must be of character type (assuming that you have an ascending sort direction).
You can force it to be numeric by using an explicit cast operation or implicitly by adding a numeric value to expression, e.g.
order by <your expression> + 0
implicit hacks, gotta love 'em
I would go with CAST, but that’s me.
https://dev.mysql.com/doc/refman/5.7/en/cast-functions.html#function_cast
My bad. I was mistaken. The query I was playing with was actually using a character type sort. Sorry.
This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.