I know a trick to make order by queries faster when we want to order by asc and desc.
For integers store a negated value.
So if I store
-7,-11,-8,-5,-1,-2 the order by asc will give
-11, -8, -7, 5, -2, -1 and so the actual row will be sorted desc by that column (if e.g I show the non-negated version).
Question: How do I use this trick with strings?
How is a string "negated" or reversed so that the trick works for string columns as well?
MySQL can not use an index for a query of the type:
ORDER BY col1 ASC col2 DESC
If the column I want to descent is an integer I can store the negated value and do the query as:
ORDER BY col1 ASC col2 ASC
In this case the index can be used and I will in fact get the value in descending order due to negation
-11, -8, -7, 5, -2, -1 is ascending but if you remove the negation is it descending.
My problem is that I am not clear how I could apply this approach to a string column. Can I somehow get the arithmetical value of the string?