The expression "ORDER BY 2"
must have a literal "2" in order for this to sort by the second column.
In all other cases, the expression (like in your example "locate") is applied to all rows individually. Even if it's aconstant.
That's the power of a 4th generation language!
So for example the following will
not sort the rows at all:
Code:
ORDER BY case when 1=1 then 2 else 2 end
since "2" is now a constant expression, applied to all rows individually, resulting in all rows having the same sort key.
By the same reasoning,
Code:
ORDER BY locate('A','A')
is
not the same as "ORDER BY 1": it will not sort the rows at all.